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. AHowever, preprocessor instructions can hide main unless a compiler directiveflag is fixesexplicitly thisset.
 
Example
<lang sh>$ gcc -o scriptedmain scriptedmain.c scriptedmain.h
 
$ ./scriptedmain
<lang sh>$ make
$ ./scriptedmain
Main: The meaning of life is 42
$ ./test
$ gcc -o test test.c scriptedmain.c scriptedmain.h
Test: The meaning of life is 42</lang>
$ ./test
 
Test: The meaning of life is 42</lang>
Makefile
 
<lang make>all: scriptedmain test
./scriptedmain
./test
 
<lang sh>$ gcc -o scriptedmain: scriptedmain.c scriptedmain.h
gcc -o scriptedmain -DSCRIPTEDMAIN scriptedmain.c scriptedmain.h
 
test: test.c scriptedmain.h scriptedmain.c
$ gcc -o test test.c scriptedmain.c scriptedmain.h
 
clean:
-rm scriptedmain
-rm test
-rm scriptedmain.exe
-rm test.exe</lang>
 
scriptedmain.h
Line 35 ⟶ 54:
}
 
#ifdef SCRIPTEDMAIN
int __attribute__((weak)) main(int argc, char **argv) {
 
int main() {
printf("Main: The meaning of life is %d\n", meaning_of_life());
 
return 0;
}
}</lang>
 
}#endif</lang>
 
test.c
Anonymous user