• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: external declares
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: external declares


  • Subject: Re: external declares
  • From: Charlton Wilbur <email@hidden>
  • Date: Sat, 11 Feb 2006 01:45:00 -0500


On Feb 10, 2006, at 8:25 PM, Robert Dell wrote:

they seem to think this is off topic for the cocoa list so i'll ask here.

It's not really on topic here, because it's not XCode-specific: the question would be the same if you were using Eclipse and gcc or Turbo C or Microsoft Visual C++. For basic C questions like this one, the best starting point is the comp.lang.c FAQ (http://c-faq.com/ index.html), and if you're looking for good learning resources, you should start with the comp.lang.c FAQ on that topic (http://c-faq.com/ resources/index.html).


Correctly partitioning your problem and diagnosing exactly what you're having trouble with -- in this case, knowing that your problem is a basic C problem and *not* a Cocoa, Carbon, or XCode problem -- is a crucial skill to develop, because it saves you a lot of debugging time and it saves other people a lot of annoyance. One very useful diagnostic is to ask, if I changed out the component I think is the problem, and on the support mailing lists of which I am considering asking the question -- in this case, using Turbo C rather than XCode -- would the problem persist? If the answer is "yes," then that's not the problem, and that's not where you should be asking the question.

That said, because I'm not so annoyed as to be completely unhelpful --

i broke up my 40,000 line program into smaller includes. one of which is the reqs calculator section and all routines needed to do that.
i noticed i needed to declare my variables as external references such as:
(within reqs.c)
extern long currentCircle;
extern long nextCircle;
extern long calcCircle;

This is probably sub-optimal design, especially if you're talking about 40,000 lines of code. There are very few instances in which variables with a scope of more than a single file are a good idea. A better solution is to define structures and prototype subroutines in header files, and declare variables and implement the subroutines in code files. Thus in a .h file you'd have (based on your example):


struct expskill
{
	char skillname[80];
	long skillvalue;
	long skillreqs;
	long skillneeded;
	long skillexclude;
};

void do_something_with_expskill (struct expskill *exp, int foo, int bar);
int useful_calculation (int count, struct expskill in[]);


and you'd have somewhere in a .c file:

#include "foo.h"

int main ()
{
struct expskill myarmor[8], myweapon[25], mymagic[5], mysurvival [15], mylore[13], myinstruments[5], swap;


	/* ... */

	do_something_with_expskill (&myarmor[0], 15, bar + quux);
	gnorfle = useful_calculation (8, myarmor);
}

my next question is dumbfounding to me...
why did the compiler scream at me when i didn't declare "nextCircle" as an external variable or at all because of "undeclared identifier" but it allowed "myarmor[1].skillvalue"
where did it get it's information from to know myarmor is a structure and it's dimensions but NOT know nextCircle is a simple longint value?


mind you, the compiler errored out before i added all the extern long declarations.

Compilers frequently get confused once they hit a certain number of errors; any errors past the first ones the compiler reports may be a result of that confusion. I can't diagnose further without seeing the actual code and the specific error messages.


Charlton


-- Charlton Wilbur email@hidden email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: external declares
      • From: Robert Dell <email@hidden>
References: 
 >external declares (From: Robert Dell <email@hidden>)

  • Prev by Date: Re: variable weirdness
  • Next by Date: Re: variable weirdness
  • Previous by thread: external declares
  • Next by thread: Re: external declares
  • Index(es):
    • Date
    • Thread