Hello,
I just started learning C a couple weeks ago from Kernighan and
Ritchie (first edition -- I can't afford the newer second edition), and
have really enjoyed it so far. But I am having trouble making the code
at the end of Chapter 5 -- the sort function that uses function pointers
-- to work on my machine (233 Mhz iMac, 160 MB RAM, OS 9.2 ; MPW
environment). When I try to compile sort.c with the Symantec C compiler
it gives me all sorts of strange errors about how the syntax (copied
straight from the book!) is screwed up. Now when I'm at school and
working on an OSX machine running gcc, sort.c will compile correctly
along with everything else, but the input is all wrong (the pointers
aren't working properly). I *think* I've traced the problem in the
gcc-compile to sort.c as well, but I'm not sure. I really don't like
being stalled with this because I want to continue doing the exercises
(which are really fun) that are based on this code.
Having looked at the code many times by now and made sure I copied
the base code from the book correctly, I'm at my wits end. Does anyone
know any reason why the Kernighan & Ritchie code from the end of Chapter
5 (1st edition) might not compile correctly on a Mac? I suspect it has
to do with some obscure detail involving the inner workings of the
computer (that would necessitate a different arrangement of pointers?),
or (less likely) some incompatibility with ANSI C, but I'm not sure. I'd
much appreciate any constructive advice anyone could give me... thanks.
I can provide my source files for someone to look at if you would think
it would help.
Ben da***@mail.utexas.edu 27 3336
"Ben Jacobs-Swearingen" <da***@mail.utexas.edu> wrote in message
news:da*************************@geraldo.cc.utexas .edu... I just started learning C a couple weeks ago from Kernighan and Ritchie (first edition -- I can't afford the newer second edition), and have really enjoyed it so far. But I am having trouble making the code at the end of Chapter 5 -- the sort function that uses function pointers
(snip)
There are some things in K&R C that just don't work anymore.
You might see if you can get the book from the library. I always did think
it was a little expensive, though.
You also might try to find a used copy. If you post the error messages,
someone might explain the difference, if any. At this point it is probably
better not to learn K&R C. The book is nice for its historical value,
though. Keep the book, but be careful how you use it.
-- glen
On Fri, 31 Oct 2003, Ben Jacobs-Swearingen wrote: I just started learning C a couple weeks ago from Kernighan and Ritchie (first edition -- I can't afford the newer second edition), and have really enjoyed it so far. But I am having trouble making the code at the end of Chapter 5 -- the sort function that uses function pointers -- to work on my machine
My copy of K&R1 is elsehome this semester, but if you'll cut and
paste the code you're trying to compile, I (and of course others)
will be glad to take a look and tell you what's right, what's
wrong and what used to be right but isn't anymore. :)
If I recall correctly, K&R doesn't start getting into platform-
specific stuff until chapter 7 or 8, so it's almost certainly a
problem in your typing-in of the program. But it's true that
some of the stuff in K&R1 isn't legal C anymore, too.
Oh, and is this code from K&R, or code you wrote as the solution
to one of the K&R exercises? When you post the code, please
indicate which it is, just in case we can't tell by looking. :)
HTH,
-Arthur My copy of K&R1 is elsehome this semester, but if you'll cut and paste the code you're trying to compile, I (and of course others) will be glad to take a look and tell you what's right, what's wrong and what used to be right but isn't anymore. :)
Alright, here's the code sort.c that won't compile at home. It's copied
straight from K&R (page 116 of the first edition; it's at the end of the
pointers chapter where they talk about function pointers), as I was
trying to get the base program working before I went on to do the
exercises:
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */
char *v[]; /* into increasing order */
int n;
int (*comp)(), (*exch)();
{
int gap, i, j;
for(gap = n/2; gap > 0; gap /= 2)
for(i = gap; i < n; i++)
for(j = i-gap; j >= 0; j -= gap) {
if((*comp)(v[j], v[j+gap]) <= 0)
break;
(*exch)(&v[j], &v[j+gap]);
}
}
looked at it again this morning and it still seems the same as the
Kernighan code (on page 116 of the first edition; don't even know if
it's included in the second edition). When I try to run it through the
Symantec C compiler at home it screams at me:
---
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */
^
File "sort.c"; line 1 #Error: identifier expected
#-----------------------
int (*comp)(), (*exch)();
^
File "sort.c"; line 4 #Error: ')' expected
#-----------------------
if((*comp)(v[j], v[j+gap]) <= 0)
^
File "sort.c"; line 11 #Error: expression expected
#-----------------------
if((*comp)(v[j], v[j+gap]) <= 0)
^
File "sort.c"; line 11 #Warning 6: value of expression is not used
#-----------------------
break;
^
File "sort.c"; line 12 #Warning 6: value of expression is not used
#-----------------------
break;
^
File "sort.c"; line 12 #Error: ';' expected
#-----------------------
(*exch)(&v[j], &v[j+gap]);
^
File "sort.c"; line 13 #Error: undefined identifier 'exch'
---
I know that function declarations are somewhat different in ANSI C, and
have tried declaring the function as
sort(char *v[], int n, (*comp)(), (*exch)())
but it doesn't make any difference. I'm going to school soon and I'll
keep on investigating the problem wit gcc -- hope to hear back from you
guys soon. I appreciate the patience with a non-computer-expert newbie!
Decided to bite the bullet and order the book anyway, as you said, glen,
there's little point trying to learn a version of C designed for the
PDP-11 and its contemporaries.
B da***@Mail.utexas.edu
"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message
news:Pi**********************************@unix48.a ndrew.cmu.edu... On Fri, 31 Oct 2003, Ben Jacobs-Swearingen wrote: I just started learning C a couple weeks ago from Kernighan and Ritchie (first edition -- I can't afford the newer second edition), and have really enjoyed it so far. But I am having trouble making the code at the end of Chapter 5 -- the sort function that uses function pointers -- to work on my machine
My copy of K&R1 is elsehome this semester, but if you'll cut and paste the code you're trying to compile, I (and of course others) will be glad to take a look and tell you what's right, what's wrong and what used to be right but isn't anymore. :) If I recall correctly, K&R doesn't start getting into platform- specific stuff until chapter 7 or 8, so it's almost certainly a problem in your typing-in of the program. But it's true that some of the stuff in K&R1 isn't legal C anymore, too.
Well, K&R allow writing into string constants, though I don't remember where
in the book they do that. That could be a problem really fast, though.
That is the first one I think of, though not related to function pointers.
-- glen
Figured it out -- had a bad pointer declaration in main() -- thanks for
the patience!
B da***@mail.utexas.edu
"Ben Jacobs-Swearingen" <da***@mail.utexas.edu> wrote in message
news:311020031136453426%da***@mail.utexas.edu... Figured it out -- had a bad pointer declaration in main() -- thanks for the patience!
Could you explain a little more? Bad declarations in main shouldn't cause
those problems.
Since C doesn't allow internal functions, though, if you had the wrong
number of } I might understand those errors.
-- glen
On Fri, 31 Oct 2003 10:14:54 -0600, in comp.lang.c , Ben
Jacobs-Swearingen <da***@mail.utexas.edu> wrote: sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ char *v[]; /* into increasing order */ int n; int (*comp)(), (*exch)();
This form of function definition is obsolete, and you reallly need to
avoid it. Some compilers will complain about it nowadays. Also you're
using "implicit int" for the function itself, which is disallowed in
the newest C standard.
int sort(char **v, int n, int(*comp(), int *exch())
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ ^ File "sort.c"; line 1 #Error: identifier expected
this is the sort of error that you will get using old-style
declarations. You really really need to get a newer book than K&R1,
its over 20 years out of date.
I know that function declarations are somewhat different in ANSI C, and have tried declaring the function as
sort(char *v[], int n, (*comp)(), (*exch)())
you need to put in the two missing "int"s.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
On Fri, 31 Oct 2003 22:33:48 +0000, Mark McIntyre wrote: On Fri, 31 Oct 2003 10:14:54 -0600, in comp.lang.c , Ben Jacobs-Swearingen <da***@mail.utexas.edu> wrote:
int sort(char **v, int n, int(*comp(), int *exch())
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ ^ File "sort.c"; line 1 #Error: identifier expected this is the sort of error that you will get using old-style declarations.
Why do you say that? Where's the error?
When I saw this code the only thing I could think of is
that the identifier comp is already defined as a type somewhere.
gcc 3.3.1, at least, invoked with
"gcc -Wall -W -ansi -std=c99 -pedantic -O2 -c test.c"
completes with only two warnings:
test.c:2: warning: return type defaults to `int'
test.c: In function `sort':
test.c:15: warning: control reaches end of non-void function
You really really need to get a newer book than K&R1, its over 20 years out of date.
Right!
In article <xGzob.71194$HS4.627461@attbi_s01>,
"Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote: "Ben Jacobs-Swearingen" <da***@mail.utexas.edu> wrote in message news:311020031136453426%da***@mail.utexas.edu... Figured it out -- had a bad pointer declaration in main() -- thanks for the patience!
Could you explain a little more? Bad declarations in main shouldn't cause those problems.
Since C doesn't allow internal functions, though, if you had the wrong number of } I might understand those errors.
Sure -- the problem that was screwing the gcc compiler at school was a
simple typo in the main() function -- I had a pointer where there should
have been a simple address marker (i.e. I had *c instead of c):
sort(*lineptr, nlines, strcmp, swap);
At the time I didn't know whether or not the two problems were related.
Now I know that they aren't, so you are right :)
The reason for the errors at home (the ones that prompted the original
message), as I figured out earlier tonight (after I sent that message),
is that evidently according to my compiler "comp" and "exch" already
have function definitions (probably in some header file on my computer
-- who knows). Changing the names of the functions to "c" and "e" fixed
the problem and I got a clean compile. I've had this problem
occasionally in other pieces of code, but in those cases it was more
obvious that the function names might have become part of the standard
library.
Now everything is working again and I'm plugging through the book
(which'll be discarded in favor of K&R 2, when it arrives). Thanks for
all the help, guys -- nice to know that there are some patient people
out there!
B da***@mail.utexas.edu
Mark McIntyre <ma**********@spamcop.net> wrote in message news:<8j********************************@4ax.com>. .. On Fri, 31 Oct 2003 10:14:54 -0600, in comp.lang.c , Ben Jacobs-Swearingen <da***@mail.utexas.edu> wrote:
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ char *v[]; /* into increasing order */ int n; int (*comp)(), (*exch)();
int sort(char **v, int n, int(*comp(), int *exch())
int sort(char **v, int n, int (*comp)(), int (*exch)())
{
/* ... */
}
The * binds more tightly to the left than the right in variable
declarations, so you need the parens to tell the compiler that the
variables themselves are pointers, instead of functions that return
pointers.
I think you wanted to post that, which is why your parens don't nest.
(The last paren actually closes the malformed expression begun right
after your second `int'. Your first paren is unclosed.)
On Fri, 31 Oct 2003, Ben Jacobs-Swearingen wrote: "Glen Herrmannsfeldt" <ga*@ugcs.caltech.edu> wrote: Could you explain a little more? Bad declarations in main shouldn't cause those problems. Sure -- the problem that was screwing the gcc compiler at school was a simple typo in the main() function -- I had a pointer where there should have been a simple address marker (i.e. I had *c instead of c):
sort(*lineptr, nlines, strcmp, swap);
At the time I didn't know whether or not the two problems were related. Now I know that they aren't, so you are right :)
The reason for the errors at home (the ones that prompted the original message), as I figured out earlier tonight (after I sent that message), is that evidently according to my compiler "comp" and "exch" already have function definitions (probably in some header file on my computer -- who knows). Changing the names of the functions to "c" and "e" fixed the problem and I got a clean compile. I've had this problem occasionally in other pieces of code, but in those cases it was more obvious that the function names might have become part of the standard library.
Many compilers have a "standard C" switch or two that you can turn
on if you want to compile... well... standard C. (In almost all
cases, that standard is C89, not C99, BTW.) That *should* get rid
of those spurious declarations of "comp", etc., if you can find
such a switch for your compiler.
Now everything is working again and I'm plugging through the book (which'll be discarded in favor of K&R 2, when it arrives).
Just thought I should point out that I like K&R1 a heck of a lot
more than K&R2 -- but then I already know C, so I don't have to
learn it from the book anymore. :-) But I *did* learn C on my
own from K&R1 and a few other sources, and there is one thing to
be said for the First Edition: partly because it's missing the
Second Edition's standard library reference, it's a heck of a
lot *shorter*! (Plus, you never know when an out-of-print book
might turn out to be worth something... hang onto it, at least.
;-)
-Arthur
On Fri, 31 Oct 2003 21:35:29 -0500, in comp.lang.c , Sheldon Simms
<sh**********@yahoo.com> wrote: On Fri, 31 Oct 2003 22:33:48 +0000, Mark McIntyre wrote:
On Fri, 31 Oct 2003 10:14:54 -0600, in comp.lang.c , Ben Jacobs-Swearingen <da***@mail.utexas.edu> wrote:
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ ^ File "sort.c"; line 1 #Error: identifier expected
this is the sort of error that you will get using old-style declarations.
Why do you say that? Where's the error?
Most likely its a typo, but its also possible the compiler is being
invoked in C++ mode and simply rejects pre-ansi function definitions.
I've seen some (nonconforming) C compilers that did that too.
In any events, retyping the definition in "modern" terms will almost
certainly remove the problem, either by fixing the typo, or by
silencing the compiler !
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
On 31 Oct 2003 21:11:20 -0800, in comp.lang.c , li***************@yahoo.com (August Derleth) wrote: Mark McIntyre <ma**********@spamcop.net> wrote in message news:<8j********************************@4ax.com>. .. On Fri, 31 Oct 2003 10:14:54 -0600, in comp.lang.c , Ben Jacobs-Swearingen <da***@mail.utexas.edu> wrote:
>sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ >char *v[]; /* into increasing order */ >int n; >int (*comp)(), (*exch)();
int sort(char **v, int n, int(*comp(), int *exch())
int sort(char **v, int n, int (*comp)(), int (*exch)())
Absolutely. Typing too fast, not proofreading.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Ben Jacobs-Swearingen wrote: The reason for the errors at home (the ones that prompted the original message), as I figured out earlier tonight (after I sent that message), is that evidently according to my compiler "comp" and "exch" already have function definitions (probably in some header file on my computer -- who knows). Changing the names of the functions to "c" and "e" fixed the problem and I got a clean compile. I've had this problem occasionally in other pieces of code, but in those cases it was more obvious that the function names might have become part of the standard library.
K&R is full of example functions,
which have the same name as standard functions.
It is something that you will have to continue to watch out for.
--
pete
On Sat, 01 Nov 2003 10:00:20 +0000, Mark McIntyre wrote: On Fri, 31 Oct 2003 21:35:29 -0500, in comp.lang.c , Sheldon Simms <sh**********@yahoo.com> wrote:
On Fri, 31 Oct 2003 22:33:48 +0000, Mark McIntyre wrote:
On Fri, 31 Oct 2003 10:14:54 -0600, in comp.lang.c , Ben Jacobs-Swearingen <da***@mail.utexas.edu> wrote:
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ ^ File "sort.c"; line 1 #Error: identifier expected
this is the sort of error that you will get using old-style declarations. Why do you say that? Where's the error?
Most likely its a typo,
Did you not read? I already said that the code compiled fine
with gcc 3.3.1. There was no typo.
but its also possible the compiler is being invoked in C++ mode and simply rejects pre-ansi function definitions. I've seen some (nonconforming) C compilers that did that too.
In any events, retyping the definition in "modern" terms will almost certainly remove the problem, either by fixing the typo, or by silencing the compiler !
Wrong answer. The code was fine. The problem was that the name
"comp" was already defined by the implementation. Making the
definition modern wouldn't have helped at all.
-Sheldon
On Sat, 01 Nov 2003 13:45:39 -0500, in comp.lang.c , Sheldon Simms
<sh**********@yahoo.com> wrote: On Sat, 01 Nov 2003 10:00:20 +0000, Mark McIntyre wrote:
On Fri, 31 Oct 2003 21:35:29 -0500, in comp.lang.c , Sheldon Simms <sh**********@yahoo.com> wrote:
On Fri, 31 Oct 2003 22:33:48 +0000, Mark McIntyre wrote: Most likely its a typo,
Did you not read? I already said that the code compiled fine with gcc 3.3.1. There was no typo.
Given that the OP has admitted elsethread to a typo, I stand
uncorrected. :-)
Making the definition modern wouldn't have helped at all.
I disagree. It would at the very least have rendered the error
meaningful as the compiler would have had to complain about a
redeclaration which was different.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
On Sun, 02 Nov 2003 00:24:44 +0000, Mark McIntyre wrote: On Sat, 01 Nov 2003 13:45:39 -0500, in comp.lang.c , Sheldon Simms <sh**********@yahoo.com> wrote:
On Sat, 01 Nov 2003 10:00:20 +0000, Mark McIntyre wrote:
On Fri, 31 Oct 2003 21:35:29 -0500, in comp.lang.c , Sheldon Simms <sh**********@yahoo.com> wrote:
On Fri, 31 Oct 2003 22:33:48 +0000, Mark McIntyre wrote:
Most likely its a typo,
Did you not read? I already said that the code compiled fine with gcc 3.3.1. There was no typo.
Given that the OP has admitted elsethread to a typo, I stand uncorrected. :-)
This discussion has nothing to do with the typo. The OP was using gcc
on Mac OSX at school. There the program compiled, but didn't work properly
when he ran it. THAT was caused by a typo, but that is not what we were
talking about.
We were talking the OP's problem with Symantec C on Mac OS 9 at home,
where the program didn't even compile. You said: "this is the sort of
error that you will get using old-style declarations"
I interpreted that to mean that the function would have compiled if
it had a "new style" parameter declaration list. If that's what you
meant, that was wrong. If you just meant that with old-style
declarations you can get cryptic and unhelpful error, then ok. Making the definition modern wouldn't have helped at all.
I disagree. It would at the very least have rendered the error meaningful as the compiler would have had to complain about a redeclaration which was different.
It depends on why a name-clash was occurring. In this case, you're
right.
-Sheldon
On Fri, 31 Oct 2003 10:14:54 -0600
Ben Jacobs-Swearingen <da***@mail.utexas.edu> wrote:
<snip> Alright, here's the code sort.c that won't compile at home. It's copied straight from K&R (page 116 of the first edition; it's at the end of the pointers chapter where they talk about function pointers), as I was trying to get the base program working before I went on to do the exercises:
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ char *v[]; /* into increasing order */ int n; int (*comp)(), (*exch)();
This style is obsolete and one of the many reasons you need a more up to
date reference. You should always specify the return type (void means it
does not return anything) and put the parameter list including types in
the brackets after the function name as follows:
void sort(char *v[], int n, int (*comp)(char *a,char *b),
void (*exch)(char *a[],char *b[]))
/* sort strings v[0]...v[n-1]*/
{ int gap, i, j;
for(gap = n/2; gap > 0; gap /= 2) for(i = gap; i < n; i++) for(j = i-gap; j >= 0; j -= gap) { if((*comp)(v[j], v[j+gap]) <= 0) break; (*exch)(&v[j], &v[j+gap]); } }
looked at it again this morning and it still seems the same as the Kernighan code (on page 116 of the first edition; don't even know if it's included in the second edition). When I try to run it through the Symantec C compiler at home it screams at me:
---
sort(v, n, comp, exch) /* sort strings v[0] ... v[n-1] */ ^ File "sort.c"; line 1 #Error: identifier expected
<snip>
Apart from being old style it looks OK to my and my compiler accepts
your original code with only warnings about the return type defaulting
to int and reaching the end of a function returning int without having
returned one. Neither of these warnings is required with C90.
I know that function declarations are somewhat different in ANSI C, and have tried declaring the function as
sort(char *v[], int n, (*comp)(), (*exch)())
Better, but see my suggestion further up.
but it doesn't make any difference. I'm going to school soon and I'll keep on investigating the problem wit gcc -- hope to hear back from you guys soon. I appreciate the patience with a non-computer-expert newbie!
You should find that gcc accepts it.My guess is that either you are
invoking the Symantic C compiler incorrectly or it is a buggy compiler.
Unfortunately for you problems with your specific compiler are not
topical here so you will have to investigate that somewhere else.
Decided to bite the bullet and order the book anyway, as you said, glen, there's little point trying to learn a version of C designed for the PDP-11 and its contemporaries.
It's well worth the money IMHO.
--
Mark Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spamtrap, it is real and I read it.
On Sun, 02 Nov 2003 01:23:29 -0500, in comp.lang.c , Sheldon Simms
<sh**********@yahoo.com> wrote: meant, that was wrong. If you just meant that with old-style declarations you can get cryptic and unhelpful error, then ok.
Correct. Without proper prototypes, the compiler is struggling to help
you. They were added to the language for a reason, I suspect. Making the definition modern wouldn't have helped at all.
I disagree. It would at the very least have rendered the error meaningful as the compiler would have had to complain about a redeclaration which was different.
It depends on why a name-clash was occurring. In this case, you're right.
Agreed.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
In <3F***********@mindspring.com> pete <pf*****@mindspring.com> writes: Ben Jacobs-Swearingen wrote:
The reason for the errors at home (the ones that prompted the original message), as I figured out earlier tonight (after I sent that message), is that evidently according to my compiler "comp" and "exch" already have function definitions (probably in some header file on my computer -- who knows). Changing the names of the functions to "c" and "e" fixed the problem and I got a clean compile. I've had this problem occasionally in other pieces of code, but in those cases it was more obvious that the function names might have become part of the standard library.
K&R is full of example functions, which have the same name as standard functions. It is something that you will have to continue to watch out for.
Easier said than done. How is a beginner supposed to know the names
of the standard library functions?
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Dan Pop wrote: In <3F***********@mindspring.com> pete <pf*****@mindspring.com> writes:
Ben Jacobs-Swearingen wrote:
The reason for the errors at home (the ones that prompted the original message), as I figured out earlier tonight (after I sent that message), is that evidently according to my compiler "comp" and "exch" already have function definitions (probably in some header file on my computer -- who knows). Changing the names of the functions to "c" and "e" fixed the problem and I got a clean compile. I've had this problem occasionally in other pieces of code, but in those cases it was more obvious that the function names might have become part of the standard library.
K&R is full of example functions, which have the same name as standard functions. It is something that you will have to continue to watch out for.
Easier said than done. How is a beginner supposed to know the names of the standard library functions?
He'll have to look up all of the functions from the chapters,
in the index,
to find out if they are also the names of library functions.
--
pete
pete wrote: Dan Pop wrote: K&R is full of example functions, which have the same name as standard functions. It is something that you will have to continue to watch out for.
Easier said than done. How is a beginner supposed to know the names of the standard library functions?
He'll have to look up all of the functions from the chapters, in the index, to find out if they are also the names of library functions.
I forgot that he's using K&R and not K&R2.
He's going to need a different reference. http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/
--
pete
In <3F***********@mindspring.com> pete <pf*****@mindspring.com> writes: Dan Pop wrote: In <3F***********@mindspring.com> pete <pf*****@mindspring.com> writes:
>Ben Jacobs-Swearingen wrote: > >> The reason for the errors at home >> (the ones that prompted the original message), >> as I figured out earlier tonight (after I sent that message), >> is that evidently according to my compiler "comp" and "exch" already >> have function definitions (probably in some header file on my computer >> -- who knows). >> Changing the names of the functions to "c" and "e" fixed >> the problem and I got a clean compile. I've had this problem >> occasionally in other pieces of code, but in those cases it was more >> obvious that the function names might have become part of the standard >> library. > >K&R is full of example functions, >which have the same name as standard functions. >It is something that you will have to continue to watch out for.
Easier said than done. How is a beginner supposed to know the names of the standard library functions?
He'll have to look up all of the functions from the chapters, in the index, to find out if they are also the names of library functions.
This is the last thing you want to do when reading K&R2 for the first
time: it breaks your focus on the things that really matter at that point.
You can start worrying about standard library function names later, by the
time you're fit for studying Appendix B.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
In <3F***********@mindspring.com> pete <pf*****@mindspring.com> writes: pete wrote: Dan Pop wrote:
> >K&R is full of example functions, > >which have the same name as standard functions. > >It is something that you will have to continue to watch out for. > > Easier said than done. How is a beginner supposed to know the names > of the standard library functions?
He'll have to look up all of the functions from the chapters, in the index, to find out if they are also the names of library functions.
I forgot that he's using K&R and not K&R2. He's going to need a different reference.
http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/
That document is not an accurate reference for *any* C standard (it
contains plenty of functions that are not part of the standard C89 library
and it's missing at least one function from the standard C99 library),
so why should he bother?
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Dan Pop wrote: In <3F***********@mindspring.com> pete <pf*****@mindspring.com> writes:
pete wrote: Dan Pop wrote:
> >K&R is full of example functions, > >which have the same name as standard functions. > >It is something that you will have to continue to watch out for. > > Easier said than done. How is a beginner supposed to know the names > of the standard library functions?
He'll have to look up all of the functions from the chapters, in the index, to find out if they are also the names of library functions.
I forgot that he's using K&R and not K&R2. He's going to need a different reference.
http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/
That document is not an accurate reference for *any* C standard (it contains plenty of functions that are not part of the standard C89 library and it's missing at least one function from the standard C99 library), so why should he bother?
His problem is that he's compiling functions from K&R,
some of which have the same names as some standard library functions.
Any function in K&R1, which is defined in N869,
is part of the C89 standard library.
Any function in K&R1, which is not defined in N869,
is not part of the C89 standard library.
N869 is free, and the point of using K&R1,
is that his resources are limited.
"I can't afford the newer second edition"
In <3F***********@mindspring.com> pete <pf*****@mindspring.com> writes: Dan Pop wrote: In <3F***********@mindspring.com> pete <pf*****@mindspring.com> writes:
>pete wrote: >> >> Dan Pop wrote: > >> > >K&R is full of example functions, >> > >which have the same name as standard functions. >> > >It is something that you will have to continue to watch out for. >> > >> > Easier said than done. How is a beginner supposed to know the names >> > of the standard library functions? >> >> He'll have to look up all of the functions from the chapters, >> in the index, >> to find out if they are also the names of library functions. > >I forgot that he's using K&R and not K&R2. >He's going to need a different reference. > >http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/ That document is not an accurate reference for *any* C standard (it contains plenty of functions that are not part of the standard C89 library and it's missing at least one function from the standard C99 library), so why should he bother?
His problem is that he's compiling functions from K&R, some of which have the same names as some standard library functions.
Could you, please, point out, which functions that have the same names as
some standard library functions is he using? I can't find any conflict
between the names used by the last example in chapter 5 and the standard
C library. Sure, the program uses printf, strcmp and atof, but it doesn't
define them.
His problem is that his implementation declares some of the user name
space identifiers used by that program, most likely as macros.
Any function in K&R1, which is defined in N869, is part of the C89 standard library. Any function in K&R1, which is not defined in N869, is not part of the C89 standard library.
How could this help him with his problem? Neither comp nor exch, the
identifiers creating him problems, are mentioned in N869 as macro names,
are they?
N869 is free, and the point of using K&R1, is that his resources are limited. "I can't afford the newer second edition"
It might be free, but it doesn't solve his problem. So, what exactly is
your point?
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Dan Pop wrote: Could you, please, point out, which functions that have the same names as some standard library functions is he using?
I may have misunderstood his problem.
--
pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: hellrazor |
last post by:
Hi there,
First of all, I'm very much a C++ amateur (i.e., a newb). I'm having to
program a win32 system service for my employer, and I'm almost done with
the task, but I need help with...
|
by: Lee David |
last post by:
I went to the sun site and downloaded what I hope is the development part of
java. I downloaded JDK5 with Netbeans. I installed it and now have a
folder in my program group "Netbeans". Is that...
|
by: Andy |
last post by:
Hey All,
I'm a beginner with VB.Dotnet Deployment and I'm a little confused
about some very basic deployment issues . . .
I've now created some core assemblies that will be used throughout all...
|
by: jim Bob |
last post by:
Hi,
This is probably very simple to do so if anyone can point me to the
right place for reading, it would be much appreciated.
I just want to build a very basic search form where i can enter a...
|
by: blueapricot416 |
last post by:
This is a very basic question -- but I can't find the answer after
looking for 20 minutes.
If you code something like:
function set_It() {
setTimeout('Request_Complete("apple", -72)',5000)
}...
|
by: Vincent Courcelle |
last post by:
Hello,
My question is very basic but I can't find an answer on search engines
for it.
How can I "pass" a variable to a control in a non programmatic way
(directly in the .aspx file, not through...
|
by: Stimp |
last post by:
Hi all,
I'm trying to read a particular node value from an XML file, but I've
done some searching on the net and there doesn't seem to be a very basic
example.
Basically here's what I want to...
|
by: questionit |
last post by:
Hi Experts
I need to write a small stack very basic program. It will only do the following:
- pop item
- push item
- count number of items in stack
But difficulty i have is how to...
|
by: bbatson |
last post by:
New to visual basic; trying to teach myself. Here is very basic code I am using to try to fill a text box on my form after updating a box that selects an employee ID.
Dim strsql As String
strsql...
|
by: Rik Wasmus |
last post by:
On Tue, 17 Jun 2008 00:52:16 +0200, Twayne <nobody@devnull.spamcop.net>
wrote:
Euhm, no you can't. The only thing remotely close is something like:
echo 'foo','bar';
.... which is nothing...
|
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...
|
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...
|
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: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |