Wade Ward said:
My compiler is giving me a cool one hundred errors right now for the
following.
unsigned long KISS(void)
#include <stdio.h>
int main(void)
{
unsigned long g;
static unsigned long t,x=123456789,y=362436069,z=21288629,w=14921776,c=0;
g=KISS();
printf("%lu\n", g);
return 0;
}
unsigned long KISS(){
x+=545925293;
y^=(y<<13); y^=(y>>17); y^=(y<<5);
t=z+w+c; z=w; c=(t>>31); w=t&2147483647;
return(x+y+w); }
! end source
This is my first error:
6 C:\Dev-Cpp\include\stddef.h:6, from
C:\Dev-Cpp\include\stddef.h In file included from
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/stddef.h:6,
from C:/Dev-Cpp/include/stddef.h
Is my compiler unable to find stdio.h ?
No, it's unable to process the declarations in stdio.h because you've
introduced a syntax error before the #include directive.
When you post code, please Please PLEASE indent it properly. It makes
it much easier to read. (Sometimes tab characters are mangled by
Usenet software; use spaces for indentation if at all possible.)
Judicious use of whitespace around operators is also very helpful.
Here's a copy of your code with whitespace added, and with no other
changes:
unsigned long KISS(void)
#include <stdio.h>
int main(void)
{
unsigned long g;
static unsigned long t, x = 123456789, y = 362436069, z = 21288629,
w = 14921776, c = 0;
g = KISS();
printf("%lu\n", g);
return 0;
}
unsigned long KISS()
{
x += 545925293;
y ^= (y<<13); y ^= (y>>17); y ^= (y<<5);
t = z + w + c; z = w; c = (t>>31); w = t&2147483647;
return (x + y + w);
}
Now take a look at your first line. There's a missing semicolon.
Declarations can span multiple lines, so as far as the compiler knows,
you just haven't finished the declaration yet; it continues looking
for a valid completion *in stdio.h*. Obviously it doesn't find one,
but it keeps looking until it can prove that there's an error. (It's
legal, but pretty much never a good idea, to begin a declaration in
one file and complete it in a nested include file.) A really smart
compiler might have guessed that the problem is the missing s
Also, your #include directives should always precede any of your own
code.
The trailing '}' of your KISS function is on the same line as the return
statement. Put it on a line by itself.
The name KISS is a poor choice; all-caps identifiers are
conventionally reserved for macros.
The prototype for KISS is inconsistent with the declaration;
unsigned long KISS(void)
and
unsigned long KISS()
mean different things.
When I fix the missing semicolon and move the #include directive to
the top of the file, I get complaints that x, y, z, t, w, and c are
undeclared in KISS. You declared these variables in main; they're not
visible in KISS. (Declaring them "static" affects their lifetime, not
their visibility.)
Since these variables are only used inside KISS, why not declare them
there?
I haven't a clue what your program is supposed to do, so I can't guess
whether it's correct or not.