Requesting advice how to clean up C code for validating string represents integer

  • Thread starter robert maas, see http://tinyurl.com/uh3t
  • Start date
R

Robert Maas, see http://tinyurl.com/uh3t

From: "Stephen Sprunk said:
If you're on a unix-ish system, try "man func" ...

% man func
No manual entry for func
% man strtoll
NAME
strtol, strtoll, strtoq -- convert a string value to a long, long long,
or quad_t integer
LIBRARY
Standard C Library (libc, -lc)
STANDARDS
The strtol() function conforms to ISO/IEC 9899:1990 (``ISO C89''). The
strtoll() function conforms to ISO/IEC 9899:1999 (``ISO C99''). The BSD
strtoq() function is deprecated.

Hey, I never heard of that before. Thanks.
If you work with a lot of unix-ish code, you'll see that a lot of
functions you're used to will be listed as conforming to POSIX
and _not_ C89/99. For example, compare the man pages for open()
and fopen().

% man open
(No mention of STANDARDS)
% man fopen
STANDARDS
The fopen() and freopen() functions conform to ISO/IEC 9899:1990
(``ISO C89''). The fdopen() function conforms to IEEE Std 1003.1-1988
(``POSIX.1'').
 
S

Stephen Sprunk

You have a good point. I'll try to remember to refer to it as ISO C
despite the contrary notation in the GNU C compiler that I use
here. And where there's any ambiguity about *which* edition of ISO
C, I'll refer to it as ISO C1989 or ISO C1999 (the latter being
"ISO C" per the previous sentence).

If you use the terms C89, C90, or C99, folks here will know what you're
referring to. C89 and C90 are effectively identical; the sections are just
numbered differently. For historical reasons, GCC (like many other
compilers) refers to C89 as "ANSI C".

Note that GCC compiles a language it calls "GNU89" by default
(-std="gnu89"), and "-ansi" or "-std=c89" or "-std=c90" gets you C89/C90.
"-std=c99" will get you mostly-functional C99 support, and "-std=gnu99" gets
you that plus various GCC extensions.
Unfortunately I don't have access to any document defining ISO
C1989, and the only document for ISO C1999 is a draft version which
is alleged to differ from the actual standard in various unknown
ways. If somebody in this newsgroup knows those differences,
perhaps that person could post a Web page that I could use for
reference? Not just for me, for anyone needing the info, but at the
moment mostly for me.

The differences between the draft and the final standard are minor and
nobody here will fault you for missing them. Virtually everyone here cites
n1124.pdf and not the actual standard anyways.

S
 
M

Mark McIntyre

You're definitely making my point, that for the C spec to simply
say that an lvalue is defined as something that specifies a region
but fails to say what kind of region, is not a specification at
all.

Myself, I suspect its reasonable to assume its a region of memory. Not
a region of geography, or of religious persuasion, or of politics, or
weather, or any other sort of highly irrelevant region. However I
can't help it if you're obtuse, so I'll say no more about it.
What do you mean "the meaning"?? ....
No one of those many meanings is "the meaning".

Sure Ludwig, and anytime I want to argue philosophy, I'll know where
to come. Meantime I suggest you get a grip.

http://en.wikipedia.org/wiki/Ludwig_Wittgenstein#The_Tractatus
--
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

Robert Maas, see http://tinyurl.com/uh3t

From: Richard Heathfield said:
So where does 42 exist, then?

That particular 42 exists in the article you posted, more
specifically different copies of it exist in hundreds of computers
around the world. At the abstract level there is a hierarchy of
equivalance classes ascending from those instances:
- All those copies in your actual article
- All copies of those in followup articles and other snippets of
text copied from some instance of your article.
- All instances of that number, in any form, which are casually
connected to the instances in copies of your article.
- All instances of that equal numeric value regardless of whether
casually connected or not.
 
R

Robert Maas, see http://tinyurl.com/uh3t

From: (e-mail address removed) (Richard Tobin)
Is this a metaphysical theory or an assertion about C?

It's basically an assertion about C, that C is designed to run on
Von Neumann machines, where there's a store of addressible memory,
a PC that ascends addresses consecutively except when a branch
instruction of some sort alters that sequence, instructions and
data both laid out in this addressible memory. C is merely an
abstraction of that Von Neumann machine, where you use alphanumeric
names for places where data is stored and for entry points for
functions instead of using the numerical machine addresses
directly, and where branching instructions are hidden within higher
level abstractions such as IF/WHILE statements and function calls.
 
K

Keith Thompson

I spent a long time reading/skimming all the way to the end of the
man pages, and saw no such information. I saw a reference to info
pages, so I tried info gcc, which put me into EMACS INFO mode with
no idea how to navigate it. It's been more than 20 years since I've
used EMACS INFO mode and I simply can't remember how to follow a
link there.

I'll just mention that if you have Emacs, then you have Gnus, the
newsreader I use. And you almost certainly have other good
newsreaders available to you.

I don't know what you're using now. Unless you're typing NNTP
protocol commands directly, you're using *some* newsreader. I've
never heard of a modern newsreader that doesn't automatically generate
proper attribution lines for followups.

I haven't a clue what your problem with attribution lines is, but it
should be easy to fix, one way or another, if you care to do so.
 
K

Keith Thompson

Stephen Sprunk said:
in message news:[email protected]... [...]
Unfortunately I don't have access to any document defining ISO
C1989, and the only document for ISO C1999 is a draft version which
is alleged to differ from the actual standard in various unknown
ways. If somebody in this newsgroup knows those differences,
perhaps that person could post a Web page that I could use for
reference? Not just for me, for anyone needing the info, but at the
moment mostly for me.

The differences between the draft and the final standard are minor and
nobody here will fault you for missing them. Virtually everyone here
cites n1124.pdf and not the actual standard anyways.

Right, but the most easily usable plain ASCII version is n869, which
predates the C99 standard. n1124.pdf is later than, and is based on,
the C99 standard, and the differences are clearly marked with change
bars. (I don't think the change bars were preserved when I exported
n1124.pdf to plain text.)
 
K

Keith Thompson

Keith Thompson <[email protected]> writes:
[attribution line fixed]

[...]
Ah, so it's *not* plain text, it's compressed with a nonstandard
compressor which confuses lynx (and me, using lynx to view it).

The Unix system you dial into probably has the bzip2 and bunzip2
programs.

[...]
That might be useful.


If you e-mail as an attachment (gzip preferred if not plain text),
be sure to go to my Web site to see what keyword has to be in the
Subject field so I'll arrive separated from the
hundred-spam-per-day so I'll ever see it.

If you make it available by FTP or HTTP, you can post the URL
either in the newsgroup, where I may or may not discover it via
Google search, or e-mail the URL with the Subject-field tag to
separate it from spam.

http://home.san.rr.com/smov/n1124.txt.gz

It won't be there indefinitely, so don't bother bookmarking it.
Please let me know (by posting a followup here) when you've downloaded
it.
Most of you have enough income to be able to afford a new computer
every several years and live PPP access for each such computer.

Ok, you're broke. We get it. Nobody here is responsible for that
fact, or in a position to do anything about it. Do you *have* to
bring up your personal economic situation every time you post here?
 
K

Keith Thompson

That particular 42 exists in the article you posted, more
specifically different copies of it exist in hundreds of computers
around the world. At the abstract level there is a hierarchy of
equivalance classes ascending from those instances:
- All those copies in your actual article
- All copies of those in followup articles and other snippets of
text copied from some instance of your article.
- All instances of that number, in any form, which are casually
connected to the instances in copies of your article.
- All instances of that equal numeric value regardless of whether
casually connected or not.

No, you're talking about particular *instances* of 42. The question
is, where does 42, not any instance of it, not any set of instances of
it, exist? The answer is nowhere; it has no location, and the
question is meaningless.

In C terms, &42 is an error; the language doesn't even give you a way
to *ask* where 42 is located.
 
K

Keith Thompson

(e-mail address removed) (Richard Tobin) writes: [attribution line fixed]
Is this a metaphysical theory or an assertion about C?

It's basically an assertion about C, that C is designed to run on
Von Neumann machines,
[snip]

A Von Neumann architecture is one with a single address space for both
data and code. This is by contrast to a Harvard architecture, in
which data and code are stored disjointly. Nothing in C specifies or
prefers one over the other.
 
F

Flash Gordon

Keith Thompson wrote, On 25/03/07 06:14:
(e-mail address removed) (Richard Tobin) writes: [attribution line fixed]
A value cannot exist unless it exists somewhere. There's no such
thing as just existing without being anywhere. The location where a
value exists is not itself a value, it's a place, a.k.a. location.
Is this a metaphysical theory or an assertion about C?
It's basically an assertion about C, that C is designed to run on
Von Neumann machines,
[snip]

A Von Neumann architecture is one with a single address space for both
data and code. This is by contrast to a Harvard architecture, in
which data and code are stored disjointly. Nothing in C specifies or
prefers one over the other.

Just to amplify the point, my first few years of C coding where mostly
on Harvard Architecture systems with 16 bit bytes and sizeof(short)==1,
sizeof(int)==1 and sizeof(long)==2. Oh, and the stack the processor
provided was only 8 levels and only used for return addresses, so the
compiler had to use another register to implement an additional stack for C.
 
M

Mark McIntyre

I never heard of bzip2 before.

Pardon me, but its hardly our fault if you're living in the computing
stone-age.

Bzip2 has been around for over a decade on any unix system you care to
mention, plus MacOS9, Windows and probably other platforms. (I dimly
recall compiling it for VMS5.2 or somesuch a while back).

If you /really/ have to live with nothing other than a unix shell via
VT100, then perhaps its time you considered flogging your ancient
computer collection and using hte proceeds to get dialup.
Lynx never heard of it either,

Lynx knows all about it - heck,. the linux implementation of Lynx is
/released/ in bzip format. See http://lynx.isc.org/release/
so if I ever really need such a file I can short-circuit
lynx to download it and then manually decompress it.

Read up on mime types, and how to configure lynx.

--
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

Gregor H. said:
Well, this may be true. On the other hand it's a historical fact that
"one of the main causes of the fall of the Roman Empire was that,
lacking zero, they
had no way to indicate successful termination of their C programs."
:)

Which just goes to show that you can't trust historians (any more than
you can trust journalists), because there /is/ a way to indicate
successful termination of your C program, even without zero.
 
R

Richard Heathfield

Robert Maas, see http://tinyurl.com/uh3t said:
If it was ever there in the first place, why would it be lost except
by a cruddy text converter??

Feel free to write a better one.
I never heard of bzip2 before.

Has it ever occurred to you to find out?
Lynx never heard of it either,
passes it verbatim to the VT100, which results in garbage.

And by the same reasoning, my C compiler can't parse HTML, so putting C
source onto the World Wide Web is obviously a pointless waste of time.
 
G

Gregor H.

Which just goes to show that you can't trust historians (any more than
you can trust journalists), because there /is/ a way to indicate
successful termination of your C program, even without zero.
Of course, there is a way to indicate successful termination of a C program,
even without zero, to-day! But the ancient C was far more primitive than our
modern one! (No standard, no K&R, nothing!)


G. H.
 
C

CBFalconer

Gregor H. said:
Of course, there is a way to indicate successful termination of a
C program, even without zero, to-day! But the ancient C was far
more primitive than our modern one! (No standard, no K&R, nothing!)

Note that the earliest Roman C specification didn't appear until
100, and that they didn't get a CC compiler until 200. Nero and
the burning of Rome set them back a bit. At any rate this finally
gives a rational reason for the names.
 
R

Richard Heathfield

CBFalconer said:
As long as you are gaily bandying about 42s, how about slipping me
one to substitute for my age?

Sure - just as soon as Robert tells us where 42 may be found.
 

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,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top