Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 13 Jan 2013 18:47:32 +0100
From: Szabolcs Nagy <>
Subject: Re: NULL

* Rob Landley <> [2013-01-13 08:29:20 -0600]:
> On 01/12/2013 07:31:14 AM, Rich Felker wrote:
> >It does. (int)0 is an integer constant expression. (int)(void *)0
> >happens to be semantically constant, but it's not an integer constant
> >expression.
> Really?
> Toybox main.c is doing:
>   #define NEWTOY(name, opts, flags) opts ||
>   #define OLDTOY(name, oldname, opts, flags) opts ||
>   static const int NEED_OPTIONS =
>   #include "generated/newtoys.h"
>   0;  // Ends the opts || opts || opts...
> Which basically boils down to either:
> Or:
> Then it does:
>   if (NEED_OPTIONS) call_option_parsing_stuff();
> And then dead code elimination zaps the option parsing stuff if it's
> only ever called behind and if (0). I tested this to make sure it
> worked. Years ago I actually upgraded tinycc to make that behave the
> same way gcc behaved so it could build this. (Yes, I could make it a
> compile probe setting a config symbol before the main build, but I
> didn't _need_ to.)
> So I think you're saying is that the behavior I'm depending on changed?


(int)(void*)0 is not an "integer constant expression" and it
is not a "null pointer constant", it is not an "arithmetic
constant expression" nor an "address constant", but an
implementation is allowed to accept it as a "constant expression"
(as far as i can see it is not required to though)

!(void*)0 and (void*)0 || (void*)0 are similar

in initializers they may be accepted, but the standard
does not require them to be

gcc used to be less strict integer constant expressions,
but recently it follows the standard more closely

> Sigh. Yup. When I build toybox with just "true", gcc 4.2.1 (last gpl
> release) drops out parse_optflag() but the ubuntu host toolchain no
> longer does.

i think gcc should be able to do the optimization

i guess gcc assumes that the value of 'static const' objects
may change or may not be available at compile-time for some

may be the following works:

  #define NEWTOY(name, opts, flags) opts ||
  #define OLDTOY(name, oldname, opts, flags) opts ||
  if (
  #include "generated/newtoys.h"
  0) call_option_parsing_stuff();

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.