Portability / compatibility issues

C

Chuck F.

Jack said:
I'd be very surprised if it had been. What arguments can you
provide that this would be a Good Thing(tm)?

I am repeating my argument from another thread here. Here it
doesn't require a subject change :)

You are looking at it solely from a debugging viewpoint. On the
other hand, it is highly preferable to save volatile data than to
crash because some meaningless display had no data with which to
update. The "(null)" display can also serve as a debugging aid.

I am firmly in the camp that believes functions should interpret
illegal parameters in a sensible way if possible. Treating NULL as
an empty source string certainly qualifies.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
J

Jordan Abel

Richard Heathfield said:
Keith Thompson said:
OzBob wrote:
[...]
# gcc -std=c99 -pedantic -W -Wall -O test.c
test.c:25: warning: return type of `main' is not `int'

Note: This is not to be taken lightly -- in principle, all
bets are off for a "void main" main().

In principle, yes. But in fact, I've never seen a C compiler that
misbehaves really badly given a "void main" declaration.

If you're prepared to generalise this to "given a declaration of main that
returns something other than int", I can vouch for the fact that I once
managed to crash Windows NT in a most colourful way by experimenting with
double main(void)!

Ah - the '!' invokes undefined behaviour.

Actually, that'd be a syntax error.
 
J

Jordan Abel

I'd be very surprised if it had been. What arguments can you provide
that this would be a Good Thing(tm)?

That it's how things were done in the original implementation [absent
some real reason to change it] isn't good enough? How about an easy way
to make a debug printf for a variable that may either point at a
null-terminated string or be NULL?
 
K

Keith Thompson

Jordan Abel said:
in comp.lang.c: [...]
more data points: On glibc, freebsd, and 7th edition UNIX, it's
"(null)" - i'm surprised this wasn't codified into the standard, given
its age.

I'd be very surprised if it had been. What arguments can you provide
that this would be a Good Thing(tm)?

That it's how things were done in the original implementation [absent
some real reason to change it] isn't good enough? How about an easy way
to make a debug printf for a variable that may either point at a
null-terminated string or be NULL?

printf("s = %s\n", s ? s : "(null)");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top