Anonymous user
Modulinos: Difference between revisions
→{{header|C}}: Updated C code to work in Windows as well as Unix
(→{{header|REXX}}: added more boilerplate, split a multi0-line, remove extra whitespace. -- ~~~~) |
(→{{header|C}}: Updated C code to work in Windows as well as Unix) |
||
Line 14:
{{works with|GCC}}
C programs cannot normally do scripted main, because main() is implicitly included by another program, test.c, even though scriptedmain.h omits any main() prototype.
Example
<lang sh>$ gcc -o scriptedmain scriptedmain.c scriptedmain.h▼
$ ./scriptedmain▼
<lang sh>$ make
Main: The meaning of life is 42
$ gcc -o test test.c scriptedmain.c scriptedmain.h▼
▲$ ./test
▲Test: The meaning of life is 42</lang>
Makefile
<lang make>all: scriptedmain test
./scriptedmain
./test
gcc -o scriptedmain -DSCRIPTEDMAIN scriptedmain.c scriptedmain.h
test: test.c scriptedmain.h scriptedmain.c
clean:
-rm scriptedmain
-rm test
-rm scriptedmain.exe
-rm test.exe</lang>
scriptedmain.h
Line 35 ⟶ 54:
}
#ifdef SCRIPTEDMAIN
int main() {
printf("Main: The meaning of life is %d\n", meaning_of_life());
return 0;
}
}</lang>▼
test.c
|