A simple parser

K

Keith Thompson

CBFalconer said:
Look at the first paragraph of my article. If you wish send me an
email and I will return a package with the problems. I have no
idea what and why, even putting printfs at various places,
including as the first statement in main, all fail. The problem
might be some failure in my system for all I know, and may not be
reproducible elsewhere.

I think you either missed the context or replied to the wrong article.

jacob's "WHAT FAILED?" was a reply to something I wrote, having to do
with returning values other than 0, EXIT_FAILURE, or EXIT_SUCCESS from
main().
 
R

Richard Heathfield

Keith Thompson said:

The standard return values for main() are EXIT_SUCCESS or 0 for
success, EXIT_FAILURE for failure. Any other values are non-portable.
In particular, there are real-world systems where "exit(1)" or
"return 1;" from main() will cause the program to terminate and
indicate *success* to the calling environment.

It's often possible to define return values other than the standard
ones, but they're likely to be system-specific, and they should be
clearly documented.

You didn't know that?

It is not unreasonable for a C newbie to be ignorant of the three portable
main return values, especially if they have never heard of the ISO C
Standard.

It is not unreasonable for even quite an experienced application programmer
to be ignorant of the three portable main return values, if they just
happen never to have come across the ISO C Standard.

It is not even unreasonable for a die-hard C DOSser, a Unix C wizard, a
mainframe C dwarf or a Windows C guru to be ignorant of the three portable
main return values, if they just happen never to have come across the ISO C
Standard.

What I am struggling to work out, though, is how a C compiler implementor or
maintainer could not be aware of the three portable main return values.
After all, surely a C compiler implementor or maintainer /has/ to know the
Standard thoroughly?
 
J

Joe Wright

Richard said:
Keith Thompson said:



It is not unreasonable for a C newbie to be ignorant of the three portable
main return values, especially if they have never heard of the ISO C
Standard.

It is not unreasonable for even quite an experienced application programmer
to be ignorant of the three portable main return values, if they just
happen never to have come across the ISO C Standard.

It is not even unreasonable for a die-hard C DOSser, a Unix C wizard, a
mainframe C dwarf or a Windows C guru to be ignorant of the three portable
main return values, if they just happen never to have come across the ISO C
Standard.

What I am struggling to work out, though, is how a C compiler implementor or
maintainer could not be aware of the three portable main return values.
After all, surely a C compiler implementor or maintainer /has/ to know the
Standard thoroughly?
I noticed upthread that Jacob didn't seem familiar with EBCDIC. Maybe
Jacob is just younger than we suspect. That might explain a lot.
 
J

jacob navia

Richard said:
What I am struggling to work out, though, is how a C compiler implementor or
maintainer could not be aware of the three portable main return values.
After all, surely a C compiler implementor or maintainer /has/ to know the
Standard thoroughly?

I do not care heathfield. The programs returns zero for success or
an error code. Period. If the OS is completely broken and takes an
error code in a program as a reason to shutdown and erase all data in
the hard disk it is not MY FAULT.

As far as my program is concerned, I return those values, and that is
it.

jacob
 
K

Keith Thompson

jacob navia said:
I do not care heathfield. The programs returns zero for success or
an error code. Period. If the OS is completely broken and takes an
error code in a program as a reason to shutdown and erase all data in
the hard disk it is not MY FAULT.

Why do you not care? Do you not agree that a C compiler implementor
or maintainer has to know the Standard thoroughly?

Returning a exit status other than 0, EXIT_SUCCESS, or EXIT_FAILURE
does not invoke undefined behavior; it merely returns an
implementation-defined status to the environment.
As far as my program is concerned, I return those values, and that is
it.

Then your program's behavior is not portable, according to the C
standard.

If you would acknowledge that simple fact, or if you had posted it to,
say, comp.unix.programmer, I would probably be willing to make some
allowances and take a look at it. (If you had posted it to a Windows
programming group, I would never have seen it.) But even then, I
would point out that there's no *need* for such a program to make
these non-portable assumptions, and that the behavior should at least
be documented.
 
M

Mark McIntyre

I do not care heathfield.

You're as bad as each other. You won't listen to what he says, even
though he's right. He attacks everything you write, even when valid.
The programs returns zero for success or
an error code. Period. If the OS is completely broken and takes an
error code in a program as a reason to shutdown and erase all data in
the hard disk it is not MY FAULT.

Yes it is. If you wilfully cause the host to carry out such disastrous
action, or even if you negligently cause this to happen, you're no
better than a virus writer.

A good programmer /understands/ the environments he has to work in,
and doesn't do things that will upset them. If you programme only for
32-bit Intel-based Windows, then it may well be that what you propose
is fine.
However if you propose a tool in CLC, it has to be generic enough to
support a wide variety of platforms. You therefore need to understand
the differences between these, and either code for them, or round
them. Simply ignoring them is not an option, at least not for a
professional, which I believe you are. Ignoring real-world problems is
what gave us buffer overruns, abnormal programme terminations and so
forth.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
R

Richard Heathfield

Mark McIntyre said:
You're as bad as each other. You won't listen to what he says, even
though he's right. He attacks everything you write, even when valid.

Not so. It's just that what he writes isn't valid very often. In any case,
I'm making a conscious effort nowadays *not* to point out Jacob Navia's
mistakes, since doing so was taking up too much of my time.

<snip>
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top