Timeline for Pseudoportable C script pattern - follow-up
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 11, 2017 at 14:46 | history | edited | Toby Speight | CC BY-SA 3.0 |
Explain what's different, to make it quicker to see what's happening here.
|
Aug 11, 2017 at 14:03 | comment | added | Edward | @TobySpeight: That's true; a zero-length file would exist. | |
Aug 11, 2017 at 14:00 | comment | added | Toby Speight |
If compilation fails, nothing is written to the target - but it does exist, because mktemp created it. Good point that you can unlink() the program text immediately (at least on POSIX systems; I'm not sure how Cygwin behaves). An alternative to allowing shell to expand variables in the program source is to use preprocessor expansion (gcc -D"PROGRAM=\"$TMP_PROGRAM_FILE\"" ) to pass the name through. Or even unlink(argv[0]) , since you know exactly how you'll invoke it.
|
|
Aug 11, 2017 at 13:54 | comment | added | Edward |
@TobySpeight: If compilation fails because a header is missing, then no target is created and there is nothing to delete. If it crashes at runtime, it will not be deleted unless the unlink has already been executed. If that's a concern, unlink could be executed earlier, minimizing (but not eliminating) that possibility.
|
|
Aug 11, 2017 at 13:47 | comment | added | Toby Speight | How does the program file get removed if it crashes or the compilation fails (perhaps because one of your target systems is missing a necessary header file)? | |
Nov 28, 2015 at 16:53 | comment | added | Edward | @chicks: The last line in the script runs the program and since it's the last thing that runs, its return value is automatically used as the return value for the script. | |
Nov 28, 2015 at 16:23 | comment | added | chicks |
Did you intend to exec the executable so that the return values got passed back? Otherwise, can you explain why you left those lines out?
|
|
Nov 28, 2015 at 12:07 | history | answered | Edward | CC BY-SA 3.0 |