473,287 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

First attempt to use strtoll: What am I doing wrong?

Here's the source:
#include <stdio.h>
#include <errno.h>
main () {
char* str = "9999999999";
long long int llin; char* endptr; /* Set by strtoll */
int nch;
errno = 0;
llin = strtoll(str, &endptr, 10);
printf("errno=%d\n", errno);
nch = endptr-str;
printf("It processed %d digits.\n", nch);
printf("N=%lld\n", llin);
}

Here's the output.
errno=0
It processed 10 digits.
N=1410065407

I expected that last line to print the correct long long value, all 9's.
Feb 12 '07 #1
15 8954
On Sun, 11 Feb 2007 20:45:23 -0800, re*****@yahoo.com (robert maas,
see http://tinyurl.com/uh3t) wrote in comp.lang.c:
Here's the source:
#include <stdio.h>
#include <errno.h>
main () {
Make that:

int main()

....or even better:

int main(void)

The current C standard, the one that includes the type "long long",
has also outlawed implicit int.
char* str = "9999999999";
long long int llin; char* endptr; /* Set by strtoll */
int nch;
errno = 0;
llin = strtoll(str, &endptr, 10);
printf("errno=%d\n", errno);
nch = endptr-str;
printf("It processed %d digits.\n", nch);
printf("N=%lld\n", llin);
}

Here's the output.
errno=0
It processed 10 digits.
N=1410065407

I expected that last line to print the correct long long value, all 9's.
What does your documentation (C book, compiler on-line help, man
pages, whatever) have to say about strtoll()?

OK, I'll give you a hint: where does your documentation say that the
prototype for strtoll() lives?

Under the current C standard, it is invalid to call a function without
a declaration in scope. Under earlier C standards, it is undefined
behavior to call a function without a declaration in scope if the
function returns anything other than an int.

And finally, what does your documentation say about invoking your
compiler in a way that it will warn you when you call a function
without a prototype in scope?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Feb 12 '07 #2
robert maas, see http://tinyurl.com/uh3t wrote:
Here's the source:
#include <stdio.h>
#include <errno.h>
main () {
char* str = "9999999999";
long long int llin; char* endptr; /* Set by strtoll */
int nch;
errno = 0;
llin = strtoll(str, &endptr, 10);
printf("errno=%d\n", errno);
nch = endptr-str;
printf("It processed %d digits.\n", nch);
printf("N=%lld\n", llin);
}

Here's the output.
errno=0
It processed 10 digits.
N=1410065407

I expected that last line to print the correct long long value, all 9's.
And I would expect you to use decent settings for diagnostics.
There are two lines added below and one changed. Notice the output.

#include <stdio.h>
#include <errno.h>
#include <stdlib.h /* mha: added for strtoll */

int main(void)
{
char *str = "9999999999";
long long int llin;
char *endptr; /* Set by strtoll */
int nch;
errno = 0;
llin = strtoll(str, &endptr, 10);
printf("errno=%d\n", errno);
nch = endptr - str;
printf("It processed %d digits.\n", nch);
printf("N=%lld\n", llin);
return 0;
}

[output]
errno=0
It processed 10 digits.
N=9999999999

Feb 12 '07 #3
From: Jack Klein <jackkl...@spamcop.net>
What does your documentation (C book, compiler on-line help, man
pages, whatever) have to say about strtoll()?
OK, I'll give you a hint: where does your documentation say that the
prototype for strtoll() lives?
Well, it's my impression that the header file is supposed to tell
the compiler what the prototype is, so it can compile correct
linkage, and also tell the loader where to find the actual module
to load, so the function will be defined at runtime, so the loader
won't bomb with unresolved symbol. So I assumed if the loader
doesn't complain that it can't find the actual function, then the
correct header file must have been included.

But I looked in the online doc again, and I see it says:
#include <stdlib.h; #include <limits.h>
So I put in that first one, didn't bother with limits, and that
fixed the problem. Thanks!!
And finally, what does your documentation say about invoking your
compiler in a way that it will warn you when you call a function
without a prototype in scope?
Well I took the stdlib include back out, and tried
-Wmissing-prototypes, but that complained about the three functions
I'm defining, and didn't complain about strtoll.
Then I tried -Wmissing-declarations, which likewise complained
about my own functions but didn't mention strtoll.
Then I tried -Wimplicit-function-declaration, and it said:
tryll.c: In function `tryParseLliTalk':
tryll.c:52: warning: implicit declaration of function `strtoll'
Aha!! Thanks again.

Hmm, I wonder if -Wmain checks for those other things you
mentionned ... nope. -pedantic ? Nope, just complains repeatedly:
warning: ANSI C does not support `long long'

-Wall gives a whole bunch (new expanded version of program I
haven't yet posted):

tryll.c: In function `printflld':
void printflld(long long int n) {

tryll.c:5: warning: int format, different type arg (arg 2)
if ((n>=0) && (n<=9)) printf("%d", n);
(oops, that should be)
if ((n>=0) && (n<=9)) printf("%lld", n);

tryll.c:8: warning: int format, different type arg (arg 2)
printf("%d", n%10);
(OK, I can cast that safely:)
printf("%d", (int)(n%10));
(Yeah, I almost made the mistake of omitting parens around whole n%10, phew!)

tryll.c: In function `tryParseLliTalk':
tryll.c:52: warning: implicit declaration of function `strtoll'
(yeah, putting the include back in)

tryll.c: At top level:
tryll.c:66: warning: return-type defaults to `int'
main () {
OK, there we go, what you said earlier:
int main (void) {

tryll.c: In function `main':
tryll.c:77: warning: control reaches end of non-void function
OK, I'll do this:
return(0);

gcc tryll.c -Wall
(No warnings!)

Anyway, here's part of what I was going to post before I saw your
reply but this is now moot:

Update from previous posting:
I saw this note:
<http://gcc.gnu.org/ml/gcc-prs/2002-05/msg00695.html>
wherein there's alleged to be a bug in the printf %lld format
directive, so maybe I'm not doing anything wrong with strtoll, it's
getting the correct value parsed, but then the printf %lld is
showing garbage. So I wrote my own (recursive) decimal-print
function to see what value is *really* in the long long int
variable assigned from strtoll. Well I get the same printout as
sprint does, so the %lld format directive isn't the problem. I'm
really getting a bad result from strtoll. So then I wrote my own
substitute for strtoll, and *now* I'm getting the correct long long
int value, which prints correctly via both the %lld directive and
my own %lld substitute.
Feb 12 '07 #4
On Sun, 11 Feb 2007 23:59:09 -0800, in comp.lang.c , re*****@yahoo.com
(robert maas, see http://tinyurl.com/uh3t) wrote:
>From: Jack Klein <jackkl...@spamcop.net>
What does your documentation (C book, compiler on-line help, man
pages, whatever) have to say about strtoll()?
OK, I'll give you a hint: where does your documentation say that the
prototype for strtoll() lives?

Well, it's my impression that the header file is supposed to tell
the compiler what the prototype is,
Typically the header /contains/ the prototype.
>so it can compile correct
linkage, and also tell the loader where to find the actual module
to load,
no, thats generally the job of the user (via commandline args,
environment variables etc). The header just tells the compiler what
the function looks like.
>so the function will be defined at runtime, so the loader
won't bomb with unresolved symbol. So I assumed if the loader
doesn't complain that it can't find the actual function, then the
correct header file must have been included.
No, it just means your programme compiled. How your envrionment
handles programme loading isn't defined by the compiler.

--
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
Feb 12 '07 #5

"robert maas, see http://tinyurl.com/uh3t" <re*****@yahoo.comwrote in
message news:re***************@yahoo.com...
From: Jack Klein <jackkl...@spamcop.net>
What does your documentation (C book, compiler on-line help, man
pages, whatever) have to say about strtoll()?
OK, I'll give you a hint: where does your documentation say that the
prototype for strtoll() lives?

Well, it's my impression that the header file is supposed to tell
the compiler what the prototype is, so it can compile correct
linkage, and also tell the loader where to find the actual module
to load, so the function will be defined at runtime, so the loader
won't bomb with unresolved symbol. So I assumed if the loader
doesn't complain that it can't find the actual function, then the
correct header file must have been included.

But I looked in the online doc again, and I see it says:
#include <stdlib.h; #include <limits.h>
So I put in that first one, didn't bother with limits, and that
fixed the problem. Thanks!!
And finally, what does your documentation say about invoking your
compiler in a way that it will warn you when you call a function
without a prototype in scope?

Well I took the stdlib include back out, and tried
-Wmissing-prototypes, but that complained about the three functions
I'm defining, and didn't complain about strtoll.
Then I tried -Wmissing-declarations, which likewise complained
about my own functions but didn't mention strtoll.
Then I tried -Wimplicit-function-declaration, and it said:
tryll.c: In function `tryParseLliTalk':
tryll.c:52: warning: implicit declaration of function `strtoll'
Aha!! Thanks again.

Hmm, I wonder if -Wmain checks for those other things you
mentionned ... nope. -pedantic ? Nope, just complains repeatedly:
warning: ANSI C does not support `long long'
<OT>
I believe if you check -pedantic again, it does indeed complain.
Additionally you can stop it from complaining about long long
by telling it which stardard to complain about i.e. std=c99.
</OT>
Feb 12 '07 #6
robert maas wrote:
>... it's my impression that the header file is supposed to tell
the compiler what the prototype is, so it can compile correct
linkage, and also tell the loader where to find the actual module
to load, so the function will be defined at runtime, so the loader
won't bomb with unresolved symbol. So I assumed if the loader
doesn't complain that it can't find the actual function, then the
correct header file must have been included.
Although it would be possible for a C implementation to work that way,
most do not.
In the general case, including the header only provides the compiler
with information on the function's parameters and return type, so that
it may generate correct code.
The linker/loader receives a list of the libraries that should be
included via a totally separated mechanism, including a small list of
"default" libraries.

If in your case the linker did not complain about missing symbols, it
is only because the functions in question were in one of libraries
used by default.

Roberto Waltman

[ Please reply to the group,
return address is invalid ]
Feb 12 '07 #7
re*****@yahoo.com (robert maas, see http://tinyurl.com/uh3t) writes:
[...]
Update from previous posting:
I saw this note:
<http://gcc.gnu.org/ml/gcc-prs/2002-05/msg00695.html>
wherein there's alleged to be a bug in the printf %lld format
directive, so maybe I'm not doing anything wrong with strtoll, it's
getting the correct value parsed, but then the printf %lld is
showing garbage. So I wrote my own (recursive) decimal-print
function to see what value is *really* in the long long int
variable assigned from strtoll. Well I get the same printout as
sprint does, so the %lld format directive isn't the problem. I'm
really getting a bad result from strtoll. So then I wrote my own
substitute for strtoll, and *now* I'm getting the correct long long
int value, which prints correctly via both the %lld directive and
my own %lld substitute.
The strtoll() function is new in C99 (obviously, since long long
didn't exist prior to C99). It's possible that your library and your
headers are out of synch; specifically that your library implements
the strtoll() function, but your <stdlib.hheader doesn't provide a
prototype for it.

Crank up your compiler's warning levels and see if you get a warning
about a missing declaration for strtoll() even if you've include
<stdlib.h>. Write a one-line C source file:
#include <stdlib.h>
and, if your compiler supports it, examine the preprocessor's output
<OT>gcc -E</OT>, and see if there's a prototype for strtol() but not
for strtoll().

If this is the problem, a workaround is to provide your own prototype
for strtoll():

unsigned long long int strtoull(
const char * restrict nptr,
char ** restrict endptr,
int base);

But this might cause problems if your implementation *does* properly
support strtoll().

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 12 '07 #8
robert maas, see http://tinyurl.com/uh3t wrote:
>From: Jack Klein <jackkl...@spamcop.net>
What does your documentation (C book, compiler on-line help, man
pages, whatever) have to say about strtoll()?
OK, I'll give you a hint: where does your documentation say that the
prototype for strtoll() lives?

Well, it's my impression that the header file is supposed to tell
the compiler what the prototype is, so it can compile correct
linkage, and also tell the loader where to find the actual module
to load, so the function will be defined at runtime, so the loader
won't bomb with unresolved symbol. So I assumed if the loader
doesn't complain that it can't find the actual function, then the
correct header file must have been included.

But I looked in the online doc again, and I see it says:
#include <stdlib.h; #include <limits.h>
So I put in that first one, didn't bother with limits, and that
fixed the problem. Thanks!!
>And finally, what does your documentation say about invoking your
compiler in a way that it will warn you when you call a function
without a prototype in scope?

Well I took the stdlib include back out, and tried
-Wmissing-prototypes, but that complained about the three functions
I'm defining, and didn't complain about strtoll.
Then I tried -Wmissing-declarations, which likewise complained
about my own functions but didn't mention strtoll.
Then I tried -Wimplicit-function-declaration, and it said:
tryll.c: In function `tryParseLliTalk':
tryll.c:52: warning: implicit declaration of function `strtoll'
Aha!! Thanks again.

Hmm, I wonder if -Wmain checks for those other things you
mentionned ... nope. -pedantic ? Nope, just complains repeatedly:
warning: ANSI C does not support `long long'

-Wall gives a whole bunch (new expanded version of program I
haven't yet posted):

tryll.c: In function `printflld':
void printflld(long long int n) {

tryll.c:5: warning: int format, different type arg (arg 2)
if ((n>=0) && (n<=9)) printf("%d", n);
(oops, that should be)
if ((n>=0) && (n<=9)) printf("%lld", n);

tryll.c:8: warning: int format, different type arg (arg 2)
printf("%d", n%10);
(OK, I can cast that safely:)
printf("%d", (int)(n%10));
(Yeah, I almost made the mistake of omitting parens around whole n%10, phew!)

tryll.c: In function `tryParseLliTalk':
tryll.c:52: warning: implicit declaration of function `strtoll'
(yeah, putting the include back in)

tryll.c: At top level:
tryll.c:66: warning: return-type defaults to `int'
main () {
OK, there we go, what you said earlier:
int main (void) {

tryll.c: In function `main':
tryll.c:77: warning: control reaches end of non-void function
OK, I'll do this:
return(0);

gcc tryll.c -Wall
(No warnings!)

Anyway, here's part of what I was going to post before I saw your
reply but this is now moot:

Update from previous posting:
I saw this note:
<http://gcc.gnu.org/ml/gcc-prs/2002-05/msg00695.html>
wherein there's alleged to be a bug in the printf %lld format
directive, so maybe I'm not doing anything wrong with strtoll, it's
getting the correct value parsed, but then the printf %lld is
showing garbage. So I wrote my own (recursive) decimal-print
function to see what value is *really* in the long long int
variable assigned from strtoll. Well I get the same printout as
sprint does, so the %lld format directive isn't the problem. I'm
really getting a bad result from strtoll. So then I wrote my own
substitute for strtoll, and *now* I'm getting the correct long long
int value, which prints correctly via both the %lld directive and
my own %lld substitute.
Have a look..

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(void) {
char *str = "9999999999";
long long int llin;
char *endptr; /* Set by strtoll */
int nch;
errno = 0;
llin = strtoll(str, &endptr, 10);
printf("errno=%d\n", errno);
nch = endptr - str;
printf("It processed %d digits.\n", nch);
printf("N=%lld\n", llin);
return 0;
}

...which gives me..

errno=0
It processed 10 digits.
N=9999999999

There's not much difference between yours and mine. What is it? :-)

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Feb 13 '07 #9
From: Joe Wright <joewwri...@comcast.net>
Have a look..
(snipped, refer to <hK******************************@comcast.com>)
There's not much difference between yours and mine. What is it? :-)
My *current* version (last edited Feb 11 23:55 PST) looks like this:

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

void printflld(long long int n) {
if ((n>=0) && (n<=9)) printf("%lld", n);
else if (n>9) {
printflld(n/10);
printf("%d", (int)(n%10));
} else {
long long int nneg;
printf("-");
nneg = -n;
if (nneg>0) { /* If n was negative but not most-negative possible. */
printflld(nneg);
} else printf("9223372036854775808"); /* N = most negative long long int */
}
}

/* Requires snum to immediately start with minus sign or first digit.
Doesn't handle leading whitespace nor plus sign. Treats empty string
as zero. Doesn't handle any base except decimal. Doesn't report end
of digits parsed via second parameter. Otherwise should behave as strtoll
was advertised. It *does* set errno in case of overflow! */
long long int mystrtoll(char* snum) {
int sign = 1;
long long int val = 0;
char* ptr = snum;
if (*ptr == '-') {
sign = -1;
ptr++;
}
while (1) {
char ch = *ptr;
if (('0' <= ch) && (ch <= '9')) {
int digval = (ch-'0')*sign;
val = val*10 + digval;
if (digval != val%10) {
errno = ERANGE;
return(-1);
}
ptr++;
} else break;
}
return(val);
}

void tryParseLliTalk(char* str) {
long long int llin; char* endptr; /* Set by strtoll */
int nch;
printf("\n** String is [%s]\n", str);
errno = 0;
llin = strtoll(str, &endptr, 10);
printf("errno=%d\n", errno);
nch = endptr-str;
printf("It processed %d digits.\n", nch);
printf("N = %lld = ", llin);
printflld(llin); printf("\n");
errno = 0;
llin = mystrtoll(str);
printf("errno=%d\n", errno);
printf("N = %lld = ", llin);
printflld(llin); printf("\n");
printf("String is still [%s]\n", str);
}

int main (void) {
tryParseLliTalk("999999999");
tryParseLliTalk("-999999999");
tryParseLliTalk("9999999999");
tryParseLliTalk("-9999999999");
tryParseLliTalk("2147483647");
tryParseLliTalk("2147483648");
tryParseLliTalk("-2147483648");
tryParseLliTalk("9223372036854775807");
tryParseLliTalk("9223372036854775808");
tryParseLliTalk("-9223372036854775808");
return(0);
}

Presumably you're trying to offer corrections to the very first
version I posted. So I went back to my backup copy of that, and
used Compare Windows (feature of McSink), and found these
differences:

Your version has:
#include <stdlib.h>
but mine already got that a few days ago due to somebody else
giving me the clue before you.

Yours has return type int and args void on main, which mine also
got a day or two ago due to somebody else giving me a clue to try
-Wall.

Yours is indented 7 spaces instead of only 2 spaces for the body of
main, so I'll have to reformat yours before I can compare the rest
with mine. (Why do you deliberately make things hard for newbies?)

You've moved the * in the declaration for str, which I already know
is totally irrelevant, so why waste my time?

You've also split the two items set by strtoll, making that comment
a half truth which is a lie. I'd rather violate one-stmt-per-line
police so that I can have a single comment that refers to two
declarations on the same line, than what you did of splitting to
make a half-truth lie, or duplicating the comment onto both lines.

You've inserted spaces around the subtraction operator between two
pointers, as if that was a fucking important thing to do to make or
break a program. Why can't you stick to what's important?

You included "return 0;", which I already did in response to -Wall
in clue from the person a few days ago already. But what's the
matter with you, you're a perl programmer at heart, love to omit
the parens around arguments to functions, which works *only* when
there's exactly one argument? I prefer always use parens so the
same syntax works uniformly regardless of number of arguments.

So anyway, the only *important* thing you changed was including the
header for stdlib, so that the long long type of return value from
strtoll would be declared and cause correct linkage to be compiled.
(GNU C compiler is too dumb to keep the presumed type around at
linkage time and check against actual type of library functions, so
that a diagnostic could be reported at that time, such as "Error:
Linkage for return value from strtoll assumed type int, but library
function uses long long int instead, making the linkage
incorrect.")
Feb 14 '07 #10
re*****@yahoo.com (robert maas, see http://tinyurl.com/uh3t) writes:
[...]
Yours is indented 7 spaces instead of only 2 spaces for the body of
main, so I'll have to reformat yours before I can compare the rest
with mine. (Why do you deliberately make things hard for newbies?)
It probably didn't occur to him that changing the indentation would
cause problems. With the tool set I use, for example, it's easy to
compare two text files while ignoring whitespace.

[...]
You included "return 0;", which I already did in response to -Wall
in clue from the person a few days ago already. But what's the
matter with you, you're a perl programmer at heart, love to omit
the parens around arguments to functions, which works *only* when
there's exactly one argument? I prefer always use parens so the
same syntax works uniformly regardless of number of arguments.
You appear to have several serious misunderstandings here.

A return statement is not a function call; it is its own special kind
of statement with its own syntax. You can legally use "return(0);"
rather than "return 0;", and some programmers do so, but it's not
necessary. The parentheses are not part of the syntax of the return
statement; they're part of the expression. In other words, the
parentheses in
return(0);
serve exactly the same role as the parentheses in
x = (0);
They're unnecessary in both cases. Personally, I prefer *not* to use
extraneous parentheses on a return statement; they make it look like a
function call, but it isn't one. You can use the parentheses if you
like, of course, but people are likely to comment on it.

A function call, on the other hand, *always* requires parentheses,
regardless of the number of arguments. Even if there are no
arguments, you still need empty parentheses: "func()". (And note that
"return ();" is a syntax error.)

I won't comment on whether Joe Wright *should* have made these
stylistic changes to your program, but in this case it's a good thing
he did so and (accidentally) raised this issue.

[...]

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 14 '07 #11
From: Keith Thompson <k...@mib.org>
It probably didn't occur to him that changing the indentation
would cause problems.
It's not a problem, just a fucking nuisance that he *said* there was
only one little change but in fact there were:
- header file inclusion
- return type on main
- void args to main
- indentation
- * moved in declaration of pointer variable
- two declarations on one line, with comment that applies to both,
split so the comment incorrectly seems to apply to just one of
the two declarations
- spaces around subtraction operator
- return 0; statement at end of main
That's eight (8) completely different changes he made, and I'm
supposed to guess which of them he's referring to as:
"There's not much difference between yours and mine. What is it?"

Which of the 8 changes is "it"???
I should cross-post a copy of his posting to alt.usage.english and
ask the folks there what the referent for "it" is supposed to be.
With the tool set I use, for example, it's easy to compare two
text files while ignoring whitespace.
Does your toolset work on Macintosh System 7.5.5? If not, I can't
use it here, and your mention of it is a bit of snobbery, nyah
nyah, I have more money to buy more toolsets than you have, so nyah
nyah I'm a better person than you are because of all the money I
have. I'm stuck with what I have already, or what I can download
for free that runs on my Mac.

Yes, I could upload all the files to Unix and do the comparison
there instead of on my Mac. That would be a pain, not worth the
trouble. Easier to reformat what I have here on the Mac so a direct
character-by-character Compare Windows will tell me what I need to
know. But I wouldn't have had to do either if the other poster
hadn't changed the indentation, especially with all the *other* red
herrings he threw in to try to distract me. The indentation was the
least of my problems trying to guess which of the *other* seven
changes he was talking about.
A return statement is not a function call; it is its own special
kind of statement with its own syntax.
Ah, thanks for the "heads up". I can't find return listed in the
operator precedence chart. How does it interreact with other
operators? For example, can you say:
char* askMult5(int x) {
return x%5==0 ? "multiple of 5" : "leaves remainder";
}
and get the intended effect?
San Diego Supercomputer Center
Ah ha, no wonder you display snobbery about the powerful tools you
have that I don't have. All I have here is a 68030 CPU. Your
supercomputer could probably factor a 120-digit number, product of
two 60-digit primes, in half a second. It probably has more than 8
megabytes of RAM too! :-)
Feb 14 '07 #12
re*****@yahoo.com (robert maas, see http://tinyurl.com/uh3t) writes:
>From: Keith Thompson <k...@mib.org>
With the tool set I use, for example, it's easy to compare two
text files while ignoring whitespace.

Does your toolset work on Macintosh System 7.5.5? If not, I can't
use it here, and your mention of it is a bit of snobbery, nyah
nyah, I have more money to buy more toolsets than you have, so nyah
nyah I'm a better person than you are because of all the money I
have. I'm stuck with what I have already, or what I can download
for free that runs on my Mac.
GNU diff can do what Keith's tool can do (and it may be Keith's
tool). It is free.
>A return statement is not a function call; it is its own special
kind of statement with its own syntax.

Ah, thanks for the "heads up". I can't find return listed in the
operator precedence chart. How does it interreact with other
operators? [...]
Do you understand that a statement is different from an operator?
return is a statement, not an operator.
--
"I hope, some day, to learn to read.
It seems to be even harder than writing."
--Richard Heathfield
Feb 14 '07 #13
re*****@yahoo.com (robert maas, see http://tinyurl.com/uh3t) writes:
>From: Keith Thompson <k...@mib.org>
[...]
>With the tool set I use, for example, it's easy to compare two
text files while ignoring whitespace.

Does your toolset work on Macintosh System 7.5.5? If not, I can't
use it here, and your mention of it is a bit of snobbery, nyah
nyah, I have more money to buy more toolsets than you have, so nyah
nyah I'm a better person than you are because of all the money I
have. I'm stuck with what I have already, or what I can download
for free that runs on my Mac.
I don't know whether it works on your system or not, but I wouldn't be
at all surprised if it does. I don't know what tools are available on
different systems to compare source files. My point -- my *only*
point -- was that Joe Wright may well not have been aware of the
limitations of the tools you're using. It just might not have
occurred to him that changing the indentation would cause problems for
you. It was most likely a minor innocent mistake on his part. By
asking "Why do you deliberately make things hard for newbies?", you
ignored that possibility and assumed malice where none was evident.

The tool I use is GNU diff. It's free. Your assumption of snobbery
is baseless and insulting.

[...]
>A return statement is not a function call; it is its own special
kind of statement with its own syntax.

Ah, thanks for the "heads up". I can't find return listed in the
operator precedence chart. How does it interreact with other
operators? For example, can you say:
char* askMult5(int x) {
return x%5==0 ? "multiple of 5" : "leaves remainder";
}
and get the intended effect?
"return" is neither a function nor an operator. It's a statement.
The syntax for a return statement is either
return;
or
return <expression>;
Any decent C reference should tell you this. Do you own a copy of
K&R2?
>San Diego Supercomputer Center

Ah ha, no wonder you display snobbery about the powerful tools you
have that I don't have. All I have here is a 68030 CPU. Your
supercomputer could probably factor a 120-digit number, product of
two 60-digit primes, in half a second. It probably has more than 8
megabytes of RAM too! :-)
Somebody gave you a modified (and no doubt improved) version of the
code you posted. He may or may not have taken into account any
possible environmental limitations with which you're burdened, and he
may have misstated the extent of the changes, but you can still learn
something from it if you care to.

Or you can just continue whining.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 14 '07 #14
robert maas, see http://tinyurl.com/uh3t wrote:
From: Keith Thompson <k...@mib.org>
<snip>
With the tool set I use, for example, it's easy to compare two
text files while ignoring whitespace.

Does your toolset work on Macintosh System 7.5.5? If not, I can't
use it here, and your mention of it is a bit of snobbery, nyah
nyah, I have more money to buy more toolsets than you have, so nyah
nyah I'm a better person than you are because of all the money I
have. I'm stuck with what I have already, or what I can download
for free that runs on my Mac.
I think most file compare utilities ignore whitespace, or have a
command line switch that instructs the same.
Yes, I could upload all the files to Unix and do the comparison
there instead of on my Mac. That would be a pain, not worth the
trouble. Easier to reformat what I have here on the Mac so a direct
character-by-character Compare Windows will tell me what I need to
know. But I wouldn't have had to do either if the other poster
hadn't changed the indentation, especially with all the *other* red
herrings he threw in to try to distract me. The indentation was the
least of my problems trying to guess which of the *other* seven
changes he was talking about.
A return statement is not a function call; it is its own special
kind of statement with its own syntax.

Ah, thanks for the "heads up". I can't find return listed in the
operator precedence chart. How does it interreact with other
operators? For example, can you say:
char* askMult5(int x) {
return x%5==0 ? "multiple of 5" : "leaves remainder";
}
and get the intended effect?
return is not an operator. It's a statement. The accompanying
expression is evaluated according to the rules of C and the resolved
value is returned by the statement.

If you get the expression right, then the return statement will do
what you want. In the snippet given above, you're returning a value of
type pointer to char that points to a non-existant object.

Feb 14 '07 #15
In article <re***************@yahoo.comre*****@yahoo.com (robert maas, see http://tinyurl.com/uh3t) writes:
From: Keith Thompson <k...@mib.org>
....
A return statement is not a function call; it is its own special
kind of statement with its own syntax.

Ah, thanks for the "heads up". I can't find return listed in the
operator precedence chart. How does it interreact with other
operators?
It is also not an operator. How can it be either a function or an operator
when the statement:
return;
is allowed?
For example, can you say:
char* askMult5(int x) {
return x%5==0 ? "multiple of 5" : "leaves remainder";
}
and get the intended effect?
Of course.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 16 '07 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: slickn_sly | last post by:
is this a valid algorithm for the question above? because I'm getting these errors: c:\\TempConverter.cpp(28): error C2106: '=' : left operand must be l-value c:\\TempConverter.cpp(29): error...
7
by: Robin Siebler | last post by:
I want to use filecmp.dircmp, but it only prints to the screen, there is no way to capture the output. So I thought that I should simply be able to subclass it to return a list (Danger! Danger,...
3
by: aaj | last post by:
SQL SERVER 2000 Hi all This is my first attempt at writing a stored procedure. I have managed to get it working but its unlikely to be the best way of handling the problem. While writing it I...
16
by: Martin Joergensen | last post by:
Hi, I wanted to try something which I think is a very good exercise... I read in data from the keyboard and store them in a structure. There's a pointer called "data_pointer" which I use to...
6
by: Lex Hider | last post by:
Hi, Apologies if this is against etiquette. I've just got my first python app up and running. It is a podcast aggregator depending on feedparser. I've really only learnt enough to get this up and...
7
by: illegal.prime | last post by:
Hi all, I've got a client/server application and just wanted to ensure that this is expected behavior. I recently set the following configuration in Visual Studio: Debug->Exceptions->Break Into...
5
by: mr.newsgroupguy | last post by:
I am working in C# .NET 1.1. My app has a button on its main form that checks to see if it has access to a file on our server, just an XML file. On our server we are running W2K IIS with a...
5
by: CedricCicada | last post by:
Greetings! I want to write messages into the Windows event log. I found sevicemanager, but the source is always "Python Service", and I'd like to be a bit more descriptive. Poking around on...
12
by: Phillip B Oldham | last post by:
I'm keen on learning python, with a heavy lean on doing things the "pythonic" way, so threw the following script together in a few hours as a first-attempt in programming python. I'd like the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.