Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

EddieDom

macrumors newbie
Original poster
Jan 9, 2009
5
0
I'm porting over some old C code and wonder if there's a way to have to NOT HAVE TO include every function in a header as an external declaration?

E.g.

foo1.c

void doThis()
{
.... code ...
}
/* end of file */

foo2.c

void doThisFirst()
{
doThis();
....
}

/* end of file */

Generates an error when I compile foo2.c that "'doThis' was not declared in this scope".

I have hundreds of files like this and really don't want to have to declare every single function! Help!

Thanks.
 

zmttoxics

macrumors 65816
May 20, 2008
1,020
1
I'm porting over some old C code and wonder if there's a way to have to NOT HAVE TO include every function in a header as an external declaration?

E.g.

foo1.c

void doThis()
{
.... code ...
}
/* end of file */

foo2.c

void doThisFirst()
{
doThis();
....
}

/* end of file */

Generates an error when I compile foo2.c that "'doThis' was not declared in this scope".

I have hundreds of files like this and really don't want to have to declare every single function! Help!

Thanks.

That is what header files are for.
http://computerprogramming.suite101.com/article.cfm/c_header_files
 

EddieDom

macrumors newbie
Original poster
Jan 9, 2009
5
0
I understand that this is one of the things that headers are for. As I said, this is OLD code and works fine in other IDEs (still). It used to be (through the 1980s) an assumed part of the dev process that the linker would deal with this.

I'm sure the updated C complires have made everyone more disciplined and I'm doing this on a go forward basis, but it did used to work and, I'm assuming there's some setting that allows this old fashioned style to work in the mac dev world (still works, for example, in Borland's IDEs).
 

EddieDom

macrumors newbie
Original poster
Jan 9, 2009
5
0
I understand that this is one of the things that headers are for. As I said, this is OLD code and works fine in other IDEs (still). It used to be (through the 1980s) an assumed part of the dev process that the linker would deal with this.

I'm sure the updated C complires have made everyone more disciplined and I'm doing this on a go forward basis, but it did used to work and, I'm assuming there's some setting that allows this old fashioned style to work in the mac dev world (still works, for example, in Borland's IDEs).

Note that the reference is from 2006.. that's more than 20 years more recent than this coding style.
 

zmttoxics

macrumors 65816
May 20, 2008
1,020
1
I understand that this is one of the things that headers are for. As I said, this is OLD code and works fine in other IDEs (still). It used to be (through the 1980s) an assumed part of the dev process that the linker would deal with this.

I'm sure the updated C complires have made everyone more disciplined and I'm doing this on a go forward basis, but it did used to work and, I'm assuming there's some setting that allows this old fashioned style to work in the mac dev world (still works, for example, in Borland's IDEs).

Note that the reference is from 2006.. that's more than 20 years more recent than this coding style.

Headers weren't invented yesterday. The most common C standard is from the 80s, and hasn't changed. There are new standards - like c99, but they are not common. If you are having compile issues, perhaps providing some logs and code will help. Otherwise, header files are what you are looking for.
 

EddieDom

macrumors newbie
Original poster
Jan 9, 2009
5
0
solved

Get this, after fussing around with the compiler settings and reading the documentation about the -x compiler directive, turns out, that XCode does NOT recognize the file extension '.C'

Simply renaming the files with extension '.c' (i.e. lower case c) the files compiled file.

And, while header files were not invented yesterday, it was only moderately common in those days to declare functions in the header files (especially for functions with no return values and no parameters)... We can argue the point 'till the cows come home, but having spent the early part of my career fixing OPC, I would say it was a fairly common practice.

Thanks for your thoughts on the matter though, they did spur me on to find this (thankfully) remarkably simple solution!!!
 

idelovski

macrumors regular
Sep 11, 2008
235
0
Oddly, but .C files are treated as C++ files and .c files as C files. You can change extension or change File Type settings for the file with Get Info to "sourcecode.c.c".

It is a feature of GCC, not Xcode.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.