9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Ralph Corderoy <ralph@inputplus.demon.co.uk>
To: 9fans@cse.psu.edu
Subject: Re: macro fun [Re: [9fans] plan or side effect]
Date: Mon, 18 Mar 2002 10:33:35 +0000	[thread overview]
Message-ID: <a6tiau$nf4$1@inputplus.demon.co.uk> (raw)
In-Reply-To: <4da3d9af.0203150929.1d3154d2@posting.google.com>

Hi ozan,

> > > i'll let you figure out what t.c trivially contains to make a soup
> > > with the "optimized" macro, thanks to simple textual substitution.
> > 
> > Is t.c a strictly conforming program?  If not, you got what you asked
> > for.
> 
> according to gcc, it is strictly conforming. it compiles
> perfectly. here is more strict version:
> 
>       bent!oz| gcc -Wall -ansi -pedantic -o t t.c
>       bent!oz| ./t
>       hello boyd!
> 
> now, with -O
> 
>       bent!oz| gcc -O -Wall -ansi -pedantic -o t t.c
>       t.c:4: parse error before `__extension__'
> 
> this is absolute crap. here is t.c.

In this case, it is t.c that's crap.

>       #include <stdio.h>
>       #include <string.h>
>       
>       extern char *strcpy(char *, const char *);

You can't do that in ANSI C and expect not to get bitten.  The compiler
is allowed to implement a standard library function as a macro if they
wish, but must still implement it as a function so its address can be
taken.

If you wish to refer to the function, without knowing if a macro
exists, you are meant to do either

    #ifdef strcpy
    #undef strcpy
    #endif

or

    extern char *(strcpy)(char *, const char *);

See a book like Harbison and Steele's _C, A Reference Manual_ for more
info on writing compliant source.

IBM's AIX C compiler also #defines strcpy as an optimisation.

    $ cc -qlanglvl=ansi -E t.c | grep strcpy
            extern char     *strcpy(char *, const char *);
    extern char *__strcpy(char *,const char *);
            __strcpy(buf,"hello boyd!");

So that doesn't give the effect you intended either.

Cheers,


Ralph.


  parent reply	other threads:[~2002-03-18 10:33 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-28 17:41 [9fans] plan or side effect David Gordon Hogan
2002-03-01 10:02 ` Thomas Bushnell, BSG
2002-03-01 12:07   ` Boyd Roberts
2002-03-04 10:04     ` Thomas Bushnell, BSG
2002-03-04 17:11       ` Sean Quinlan
2002-03-04 18:23       ` ozan s yigit
2002-03-05  9:41         ` Thomas Bushnell, BSG
2002-03-05  9:56           ` Boyd Roberts
2002-03-05  9:43       ` Boyd Roberts
2002-03-08 17:30         ` Thomas Bushnell, BSG
2002-03-08 18:00           ` Dan Cross
2002-03-11 10:04             ` Ralph Corderoy
2002-03-11 10:04             ` Thomas Bushnell, BSG
2002-03-14  9:56           ` macro fun [Re: [9fans] plan or side effect] ozan s. yigit
2002-03-15 10:18             ` Thomas Bushnell, BSG
2002-03-15 10:18             ` Douglas A. Gwyn
2002-03-15 17:48               ` ozan s. yigit
2002-03-15 18:40                 ` Mike Haertel
2002-03-18 10:38                   ` ozan s yigit
2002-03-15 18:42                 ` Mike Haertel
2002-03-18 10:32                 ` Thomas Bushnell, BSG
2002-03-18 10:33                 ` Thomas Bushnell, BSG
2002-03-21 11:01                   ` ozan s yigit
2002-03-18 10:33                 ` Ralph Corderoy [this message]
2002-03-19  9:49                   ` Douglas A. Gwyn
2002-03-21 11:01                     ` Ralph Corderoy
2002-03-18 10:38                 ` AMSRL-CI-CN
2002-03-20 13:38                 ` Boyd Roberts
2002-03-18 10:38               ` ozan s. yigit
2002-03-18 13:08                 ` Wladimir Mutel
2002-03-19  9:49                   ` ozan s. yigit
2002-03-19  9:49                 ` Douglas A. Gwyn
2002-03-19 16:01                   ` ozan s yigit
2002-03-01 11:57 ` [9fans] plan or side effect Boyd Roberts
2002-03-18 11:22 macro fun [Re: [9fans] plan or side effect] forsyth
2002-03-18 17:37 ` Thomas Bushnell, BSG
2002-03-18 18:05 forsyth
2002-03-19  9:50 ` Douglas A. Gwyn
2002-03-19 10:57 forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='a6tiau$nf4$1@inputplus.demon.co.uk' \
    --to=ralph@inputplus.demon.co.uk \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).