Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Compile Question 2

Status
Not open for further replies.

xweyer

MIS
Sep 7, 2000
140
US
I've built a small Beowulf cluster and am now trying to compile some code I found online to do a rough benchmark of performance. The Beowulf software (Scyld Preview) is based on Redhat 7.2.

There are two small C programs I need to compile but I'm having no luck getting either to work. Both produce similar warning messages.

Being a complete beginner with C I have no idea how to proceed in identifying the source of these warnings. I've tried searching on the errors but haven't turned up anything that seems relevant.

I'd appreciate any guidance as to what might be going on and how best to go about correcting it.

(The compile command I've been using is "gcc -Wall -o sum sum.c")

Thanks

This is the shorter of the two c programs.

6.1 sum.c

/* Jacek Radajewski jacek@usq.edu.au */
/* 21/08/1998 */

#include <stdio.h>
#include <math.h>

int main (void) {

double result = 0.0;
double number = 0.0;
char string[80];


while (scanf("%s", string) != EOF) {

number = atof(string);
result = result + number;
}

printf("%lf\n", result);

return 0;

}

WARNINGS

sum.c:1: parse error before '/'
In file included from /usr/include/stdio.h:57,
from sum.c:6:
/usr/include/libio.h:263: parse error before "size_t"
/usr/include/libio.h:272: parse error before "size_t"
/usr/include/libio.h:368: parse error before "_IO_sgetn"
/usr/include/libio.h:368: parse error before "size_t"
/usr/include/libio.h:368: warning data definition has no tag or storage class
In file included from sum.c:6:
/usr/include/stdio.h:237: parse error before "size_t"
/usr/include/stdio.h:243: parse error before "size_t"
/usr/include/stdio.h:273: parse error before "size_t"
/usr/include/stdio.h:277: parse error before "size_t"
/usr/include/stdio.h:281: parse error before "size_t"
/usr/include/stdio.h:446: parse error before "fread"
/usr/include/stdio.h:446: parse error before "size_t"
/usr/include/stdio.h:447: warning data definition has no tag or storage class
/usr/include/stdio.h:449: parse error before "fwrite"
/usr/include/stdio.h:449: parse error before "size_t"
/usr/include/stdio.h:450: warning data definition has no tag or storage class
/usr/include/stdio.h:454: parse error before "fread_unlocked"
/usr/include/stdio.h:454: parse error before "size_t"
/usr/include/stdio.h:455: warning data definition has no tag or storage class
/usr/include/stdio.h:456: parse error before "fwrite_unlocked"
/usr/include/stdio.h:457: parse error before "size_t"
/usr/include/stdio.h:458: warning data definition has no tag or storage class
sum.c: In function `main':
sum.c:18: warning: implicit declaration of function `atof'
sum.c:22: warning: use of 'l' length character with 'f' type character

Relevant URLs
Index
Section Relating to C Code
Souce Code
 
Why use -Wall?
Try "gcc -o sum sum.c" and see if you still have any warnings.


Trojan.
 
I tried your suggestion but the warnings were the same. One thing I did catch is that the data definition errors above actually say "has no type or storage class" instead of "has no tag or storage class" as I had transcribed them above.
 
Maybe this makes no complete sense, but I'd try removing the commented lines at the top.

Cheers,
Dian
 
Remove "6.1 sum.c" before the first /*
 
Thanks to both Diancecht and xwb for putting me on the right track. The program name "6.1 sum.c" was included in the source code although I thought I'd commented it out. However , on closer examination the title was preceded with "/#" vs. "/*". The fonts in version of Gnome included in the Beowulf software are so rough that the # and * characters are almost indistinguishable as displayed on the screen. I doubt I would have ever noticed the typo if your comments hadn't focused my attention to the beginning lines of the program.

Once I fixed that the code compiled.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top