• 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: Newbie Question - #include scope
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Question - #include scope


  • Subject: Re: Newbie Question - #include scope
  • From: Eric Johnson <email@hidden>
  • Date: Wed, 10 Dec 2008 15:07:16 -0800

Hi Gil,
Normally ".c" files are each compiled separately and not included by other ".c" files. Check out
http://c-faq.com/cpp/hfiles.html


for a longer explanation.
I would guess that "testadd.c" is getting compiled on it's own and since it doesn't include "test.h", that's why you're seeing the error.


-Eric




Message: 1
Date: Wed, 10 Dec 2008 11:19:08 -0800
From: Gil Dawson <email@hidden>
Subject: Newbie Question - #include scope
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset="us-ascii"

Hi--

I am rather new to XCode (Version 2.5), still reading the User
Guide.  I'm stumped by one thing I'm seeing that I'd think would be
obvious.

I made up a little project to demonstrate this thing.  The project
contains three files (listed below); "test.c" #includes the other
two.   The first #included file declares a global variable, MyData,
and sets it.  The second #included file uses that variable.

The problem is, when I compile (command-K) the "test.c" file, the
second #included file gets an error that MyData is undeclared. Why so?

I confess to an illusion that this doesn't happen all the time.  I
could swear (but I cannot reproduce) that that compile went through
without errors a few minutes ago, before I changed something then
changed it back.  Is this possible, or should I think about changing
my coffee supplier?

--Gil

//test.c
#include <test.h>
int main(void) {
	if (MyData); //stub
	return 1;
}
#include "testadd.c"

//test.h
int MyData = 0;

//testadd.c
void foo(void) {
	if (MyData);  //<-- 'MyData' undeclared (first use in this function)
}
_______________________________________________
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


  • Prev by Date: Re: An answer re: Broken pipe error
  • Next by Date: RE: Which SDK is recommended when doing both Mac and iPhone development?
  • Previous by thread: Re: Newbie Question - #include scope
  • Next by thread: Xcode devouring all of my drive space
  • Index(es):
    • Date
    • Thread