• 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: <types.h> and other includes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: <types.h> and other includes


  • Subject: Re: <types.h> and other includes
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 23 Feb 2005 12:37:09 +0000

On 23 Feb 2005, at 01:21, Markian Hlynka wrote:

Ok, so, I have a project that compiles fine in xcode. I usually have this project compiling under various unices as well. Today, I tested the linux compile. I should add that I _also make sure this stuff compiles on the MacOS command line using make. So, once I'd changed Makefile to makefile, and other silliness, two things bothered me after moving to linux:

You shouldn't have to change Makefile to makefile; the former name is correct on Linux as well.


Starting with the lesser...

1. I had to add #include <stdlib.h> to a file when using the makefile, because it didn't know what exit() was. Why didn't xcode have a problem with this? If xcode has a bunch of automatic includes, is it feasible to disable them so I get the same errors for inclusion as I would when running make? And, if this was an xcode thing, why didn't gcc/make on OS X have trouble with this?

The problem will probably be because another header file you are using has included the definition of exit() somehow (e.g. by including <stdlib.h>) on Mac OS X, where the same header on Linux does not include stdlib.h.


2. I used a type, u_int16_t. Neither xcode nor gcc/make on OS X required me to do anything. however, on linux I had to #include <sys/types.h> Why?

The answer to this is similar to the answer to the first question. On OS X, the definition is included by something else, on Linux, it isn't.


More annoyingly, I wanted to make sure that if I had included <sys/types.h> in the mac code, it would still work. Well, first I went to xcode and command-clicked u_int16_t so see the definition. It too me to /usr/include/ppc/types.h. Upon routing around I ALSO discovered types.h files in /usr/include/sys/ and /usr/include/machine/

I'm not sure if I diffed every combination, but they are NOT all the same. What's going on here? by included sys/types.h have I overridden the /ppc/types.h? added to it?

No. <sys/types.h>, <ppc/types.h> and <machine/types.h> are all different files. The compiler identifies header files by their path, not just their name. On OS X/Darwin, <sys/types.h> actually includes <machine/types.h>, which, depending on whether you have a PPC processor or an x86 processor, either includes <ppc/types.h> or <i386/types.h>.


This is similar to the situation on Linux, where I seem to recall that <sys/types.h> includes <asm/types.h>.

And, more importantly, again, what's the deal? I want my OS X compiles, whether with xcode or makefile, to require me to include the same things as much as possible as linux will. I realize that for some things this isn't going to be possible. However, I'm writing pretty straight-up un-fancy code here.

You're always going to have to test on all the platforms to make certain that this works, however, you can make things a lot easier for yourself by always #including the files stipulated by the C standard and/or the POSIX standard. So, for instance, you should have been #including <stdlib.h> even on OS X because that is where the definition of exit() is supposed to be (generally speaking, the man pages for functions will indicate which headers they rely on, although the authoritative source for such information is really the various standards documents).


Similarly, you shouldn't expect to have u_int16_t on any given system; although it's a common name for that type, AFAIK it isn't a standard and isn't actually available on all systems (Solaris and HPUX don't have them, for instance). Instead, you should ideally #include <stdint.h>, and use uint16_t, which *is* a standard type as of C99. Of course, on systems that don't support <stdint.h>, you might have to adopt another solution instead.

Kind regards,

Alastair.

--
http://www.alastairs-place.net

_______________________________________________
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


References: 
 ><types.h> and other includes (From: Markian Hlynka <email@hidden>)

  • Prev by Date: Re: Differences between Cocoa and Cocoa-Java Projects/Targets
  • Next by Date: Re: <types.h> and other includes
  • Previous by thread: Re: <types.h> and other includes
  • Next by thread: RE: <types.h> and other includes
  • Index(es):
    • Date
    • Thread