Z
Zach
Here is my test program (just swaps 2 ints):
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int s1, s2;
s1 = 3;
s2 = 4;
printf("s1 = %d \n", s1);
printf("s2 = %d \n", s2);
swap(s1,s2);
exit(EXIT_SUCCESS);
}
swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
printf("s1 = %d \n", a);
printf("s2 = %d \n", b);
return 0;
}
When I compile there are no errors and it runs with expected results:
zu22@netrek:~$ ./foop
s1 = 3
s2 = 4
s1 = 4
s2 = 3
But why is it not complaining about no function prototype for
swap() ?
Oddly when I do add a function prototype I get an error:
On line 5 I added:
swap(int, int);
When I compile it says:
swap-foo.c:5: warning: data definition has no type or storage class
What does this mean?
I tried using the program protoize but it doesn't do anything:
zu22@netrek:~$ protoize swap-foo.c
protoize: compiling 'swap-foo.c'
protoize: converting file 'swap-foo.c'
zu22@netrek:~$ diff swap-foo.c swap-foo.c.save
zu22@netrek:~$
Zach
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int s1, s2;
s1 = 3;
s2 = 4;
printf("s1 = %d \n", s1);
printf("s2 = %d \n", s2);
swap(s1,s2);
exit(EXIT_SUCCESS);
}
swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
printf("s1 = %d \n", a);
printf("s2 = %d \n", b);
return 0;
}
When I compile there are no errors and it runs with expected results:
zu22@netrek:~$ ./foop
s1 = 3
s2 = 4
s1 = 4
s2 = 3
But why is it not complaining about no function prototype for
swap() ?
Oddly when I do add a function prototype I get an error:
On line 5 I added:
swap(int, int);
When I compile it says:
swap-foo.c:5: warning: data definition has no type or storage class
What does this mean?
I tried using the program protoize but it doesn't do anything:
zu22@netrek:~$ protoize swap-foo.c
protoize: compiling 'swap-foo.c'
protoize: converting file 'swap-foo.c'
zu22@netrek:~$ diff swap-foo.c swap-foo.c.save
zu22@netrek:~$
Zach