|
Re: learning c, example code gives error? [solved] [message #1839754 is a reply to message #1839713] |
Sat, 27 March 2021 10:22 |
Tauno Voipio Messages: 742 Registered: August 2014 |
Senior Member |
|
|
This is off-topic for Eclipse, it is just plain C programming question.
There must be a non-printing character on the complaint line or before it.
When I copied your example from the message, it gave:
--- clip clip ---
macbook2t:Desktop tauno$ gcc -o void void.c
void.c:3:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main (void)
^
void.c:3:1: note: change return type to 'int'
void main (void)
^~~~
int
1 warning generated.
-- run example --
macbook2t:Desktop tauno$ ./void
The value at vptr as an int is 255958283
The value at vptr as a char is 11
macbook2t:Desktop tauno$
--- clip clip ---
The complaint of the type of main() is correct, the proper form is:
int main(int arcg, char *argv[])
You also need to provide the return value with a return statement. The value macros for the return are in stdlib.h.
Another thing is that you're testing unhealthy pointer usage. That kind of coding is prone to produce hard-to-find bugs.
--
Tauno Voipio
|
|
|
Powered by
FUDForum. Page generated in 0.02062 seconds