[Ffmpeg-devel] More signed fun

Dave Dodge dododge
Mon Mar 27 05:34:29 CEST 2006


On Sun, Mar 26, 2006 at 04:42:10PM -0800, Loren Merritt wrote:
> In this case, one token is `-' and another token is `-1'.

Minor point: the tokens are '-', '-', and '1'.  Number tokens in C
don't have signs attached.

As a side effect this means there's actually no such thing as a
negative integer constant in C.  '-1' is an expression that negates
the integer constant '1'.  This has subtle consequences.  For example
assume the largest integer type on your system is 64 bits, and has the
typical range [-(2^63),(2^63)-1].  You can't write out its minimum
value in code like this:

  -9223372036854775808

Even though that negative value _is_ representable by an integer type,
the code produces an expression containing a positive integer constant
that's out of range.  You might see limits.h playing tricks in order
to define things like LLONG_MIN without overflowing.

> It's not "works because spaces are added", it's "spaces are added because 
> otherwise the tokens would be concatenated".

Like '-', the sequence '--' is a single punctuator token to the
preprocessor.  Also, the matching rules always grab the longest valid
token they can, so the sequence '---' consistently tokenizes as '--'
followed by '-'.

Aside: the C preprocessor is a little bit messy in that its
tokenization is context-sensitive.  The problem is that "foo" can be
either a header-name or string-literal depending on the surrounding
tokens.  Also, the rules for what is allowed between the quotes are
slightly different for those two types of tokens.  For example "\" can
be a header-name but not a string-literal.

                                                  -Dave Dodge





More information about the ffmpeg-devel mailing list