Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Oct 2002 12:45:23 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        Craig Rodrigues <rodrigc@attbi.com>, freebsd-standards@FreeBSD.ORG, freebsd-hackers@FreeBSD.ORG
Subject:   Re: Problem detecting POSIX symbolic constants
Message-ID:  <3DA72A53.9D2D61E5@mindspring.com>
References:  <20021011183032.D12170-100000@gamplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Bruce Evans wrote:
> > I know it's not fashionable to write code that's portable to
> > compilers other than GCC, but even if FreeBSD is going to ignore
> > portability for it's own source code, it's probably unreasonable
> > to expect ACE to ignore portability for theirs.
> 
> Undefined symbols being 0 in cpp in expressions was in early C compilers
> if not the original one.  Consult your archives for a posting 10-15 years
> or so ago by dmr in comp.std.c about him checking this in his archives.

You mean "in preprocessor expressions", of course.


> > This can't be the case; specifically, the sysconf() test will
> > only work at runtime, which means that the symbols had to be
> > there and resolvable at link time.
> 
> Symbols can be resolved at runtime using dlopen(), etc.  They would only
> actually be available on systems where sysconf() says that they are.

You can't depend on people using the standard C library via dlopen,
as opposed to, uh, "linking".

If you are depending on this, then you don't need sysconf: if the
symbol isn't in the library, that's an equally valid indicator,
so if the symbol lookup fail on a library open on Windows, which
does not have sysconf at all (for example), it would have to be
treated as equivalent.

In UNIX, the symbol would have to be there, because the preferred
linking technology *says* it has to be there for the link to succeed,
if the symbol is referenced.

Again, it's a *lot* easier for the programmers to say "screw this!",
and blow off the runtime code morphing.


> > Uh, the 1990 standard, which allowed "#if" is only 12 years old.
> 
> #if is in K&R1 (1978).

According to my first edition "The C Programming Language":

	12.3 Conditional compilation
	    A compiler control line of the form

			#if constant-expression

	checks whether the constant expression (see section 15)
	evaluates to non-zero.

	...

	15 Constant expressions
	    In several places C requires expressions which evaluate
	to a constant: after case, as array bounds, and in initializers.
	In the first two cases, the expression can involve only integer
	constants, character constants, and sizeof expressions, possibly
	connected by the binary operators

		+ - * / % & | ^ << >> == != < > <= >=

	or by the unary operators

		- ~

	or by the ternary operator

		?:

...no "&&" or "||"... sorry.  Also, "defined()" is not defined.

I think you will find that "&&" and "||" in #if statements are
later extensions.


The value of undefined macros in preprocessor expressions being
assumed to be zero is also not documented in the book.  I would
have to imagine that they were not considered constant expressions.


-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3DA72A53.9D2D61E5>