public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* -ansi, POSIX etc basic questions?
@ 2004-09-24 11:30 Phil Prentice
  0 siblings, 0 replies; 3+ messages in thread
From: Phil Prentice @ 2004-09-24 11:30 UTC (permalink / raw)
  To: gcc-help, gcc

Hi

  I have some basic questions around compiler definitions.  I am porting some 
code which contains a mixture of BSD & SVR4 from Solaris to Linux.

  Forgive me if some of these questions are rather basic.

  1)  I have been using the -ansi flag definition, because that seemed the 
right thing to do?  I seem to remember that -ansi will (where possible) check 
prototyping and will define the __STDC__ definition.
       Am I correct to be trying to use this -ansi flag????

  2)  The sad thing is that if I use the -ansi flag it stops many of the 'C'  
files from compiling. For example MAXNAMLEN will be undefined or things like 
u_long or S_IFDIR will not be defined.  I presume that this is related to 
compiler definitions like __USE_BSD or __USE_POSIX or __USE_XOPEN etc

       Presumably -ansi is automatically turning some of these compiler 
definitions off??

      Should I be defining these definitions (as required) when I'm building 
the 'C' files using -ansi????

       Any other suggestions?

       Currently in many cases I am simply defining these defn's as part of 
the C source.....not the most ideal solution.

  3)  Can I get the compiler to somehow list out the compiler definitions 
that it is using?

  Thank You very much for your time

  Phil Prentice

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -ansi, POSIX etc basic questions?
       [not found] <E1CAoAV-00080S-5w@monty-python.gnu.org>
  2004-09-24 11:57 ` Nathan Sidwell
@ 2004-09-24 21:02 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2004-09-24 21:02 UTC (permalink / raw)
  To: Phil Prentice; +Cc: gcc-help

Phil Prentice <philp.cheer@btinternet.com> writes:

>   1)  I have been using the -ansi flag definition, because that seemed the 
> right thing to do?  I seem to remember that -ansi will (where possible) check 
> prototyping and will define the __STDC__ definition.
>        Am I correct to be trying to use this -ansi flag????

Probably not.  In general -ansi puts the compiler into strict ANSI C
mode (really ISO C mode).  In particular it tells the header files to
restrict themselves to symbols which are defined in the ISO C
standard.  Few useful programs are written that way.

The main purpose for -ansi is to pass testsuites.  It would be useful
for programs which written in strict ISO C, but very few programs are
in fact written that way.

When compiling existing source code, -ansi is pretty much never
appropriate unless the program explicitly calls for it.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -ansi, POSIX etc basic questions?
       [not found] <E1CAoAV-00080S-5w@monty-python.gnu.org>
@ 2004-09-24 11:57 ` Nathan Sidwell
  2004-09-24 21:02 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Sidwell @ 2004-09-24 11:57 UTC (permalink / raw)
  To: Phil Prentice; +Cc: gcc-help

Phil Prentice wrote:
> Hi
> 
>   I have some basic questions around compiler definitions.  I am porting some 
> code which contains a mixture of BSD & SVR4 from Solaris to Linux.
> 
>   Forgive me if some of these questions are rather basic.
> 
>   1)  I have been using the -ansi flag definition, because that seemed the 
> right thing to do?  I seem to remember that -ansi will (where possible) check 
> prototyping and will define the __STDC__ definition.
>        Am I correct to be trying to use this -ansi flag????
> 
>   2)  The sad thing is that if I use the -ansi flag it stops many of the 'C'  
> files from compiling. For example MAXNAMLEN will be undefined or things like 
> u_long or S_IFDIR will not be defined.  I presume that this is related to 
> compiler definitions like __USE_BSD or __USE_POSIX or __USE_XOPEN etc
> 
>        Presumably -ansi is automatically turning some of these compiler 
> definitions off??
these are not compiler definitions. They come from include files.  Presumably
they are being disabled when STDC is defined.  You probably want something like

#define _POSIX somevalueorother
#define _XOPEN_SOURCE  somevalueorother
before #including sytem files.  You'll need to consult your system
documentation (or grep /usr/include/**/*.h for their uses.
/usr/include/features.h might be a good one to look in.)

> 
>       Should I be defining these definitions (as required) when I'm building 
> the 'C' files using -ansi????

Do not define the __USE_BSD type things, use the higher level switches
I just mentioned.
> 
>        Any other suggestions?
> 
>        Currently in many cases I am simply defining these defn's as part of 
> the C source.....not the most ideal solution.


> 
>   3)  Can I get the compiler to somehow list out the compiler definitions 
> that it is using?
Perhaps -E -dD will help you here.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-09-24 21:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-24 11:30 -ansi, POSIX etc basic questions? Phil Prentice
     [not found] <E1CAoAV-00080S-5w@monty-python.gnu.org>
2004-09-24 11:57 ` Nathan Sidwell
2004-09-24 21:02 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).