You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Empty string is the smallest valid c code - it has no executable code and no data, but it remains valid. You can compile it to an object file (.o) and a shared library (.so on UNIX). So the c file in this repo should be an empty file, as this is exactly the smallest valid file of this type.
What you can't do with it, is to link it as a program, as that requires exactly one main function. That is what you're aiming for in the current c file. But there are a few problems with this file (int main;):
As mentioned above, this is not the smallest possible c file.
The file produces undefined behavior. Normally, main is a function. You've declared main as an int variable. In such case, the C standard AFAIK doesn't specify what happens, although it's permitted (i.e. it's undefined behavior). What a c compiler will typically do in this case, is to put the contents of main in an executable section and call it. This actually allows to run any machine code by assigning an array to main. Anyway, in this case, calling main causes the computer to run machine code consisting of one or more zero bytes (depending on the size of int), which e.g. on my linux x86-64 system causes a segmentation fault. To fix this, you can make main an empty function, by adding {} (returning 0 from main is implicit).
The type (int) is not needed, int is an implicit type used in c when none is given. Also, the ending semicolon is not needed as well.
Given the above, I propose the following:
Make c.c an empty file.
Add another file, maybe called c_program.c, with the following contents: main(){}.
The text was updated successfully, but these errors were encountered:
Empty string is the smallest valid c code - it has no executable code and no data, but it remains valid. You can compile it to an object file (
.o
) and a shared library (.so
on UNIX). So the c file in this repo should be an empty file, as this is exactly the smallest valid file of this type.What you can't do with it, is to link it as a program, as that requires exactly one main function. That is what you're aiming for in the current c file. But there are a few problems with this file (
int main;
):main
is a function. You've declaredmain
as an int variable. In such case, the C standard AFAIK doesn't specify what happens, although it's permitted (i.e. it's undefined behavior). What a c compiler will typically do in this case, is to put the contents of main in an executable section and call it. This actually allows to run any machine code by assigning an array to main. Anyway, in this case, calling main causes the computer to run machine code consisting of one or more zero bytes (depending on the size of int), which e.g. on my linux x86-64 system causes a segmentation fault. To fix this, you can makemain
an empty function, by adding{}
(returning 0 from main is implicit).int
) is not needed,int
is an implicit type used in c when none is given. Also, the ending semicolon is not needed as well.Given the above, I propose the following:
main(){}
.The text was updated successfully, but these errors were encountered: