You don't need to be targeting older operating systems to encounter quite large differences. You only need to look as far as the c lib.Yeah, i wanna see example : )
For example: your program accepts flags (NOTE: typed without access to compiler). real world hint: your compiler accepts arguments in any order.
C:
#include <unistd.h>
#include <stdio.h>
/**
* This code should act as demo'd below because BSD getopt(3) acts as:
* "
* When all options have been processed (i.e., up to the first
* non-option argument), getopt() returns -1.
* "
* EXAMPLE RUN:
* [test]cc -o test_getopt test_getopt.c
* [test]./test_getopt -n -f file.in -d default.in key=value
* file_string: file.in
* default_string: default.in
* arg_string: key=value
* show_key: 1
* [test]./test_getopt key=value -n -f file.in -d default.in
* file_string: (null)
* default_string: (null)
* arg_string: key=value
* show_key: 0
* [test]
*/
int main(int argc, char *argv[]) {
char *file_string = NULL;
char *default_string = NULL;
char *arg_string = NULL;
int keyvalue_output = 0;
int opt;
while ((opt = getopt(argc, argv, "f:d:n")) != -1) {
switch (opt) {
case 'f': file_string = optarg; break;
case 'd': default_string = optarg; break;
case 'n': keyvalue_output = 1; break;
default:
fprintf(stderr, "Usage: %s -f <configuration file> [-d <defaults file>] [-n] [key[=value]]\n", argv[0]);
}
}
if (optind < argc) arg_string = argv[optind];
printf(" file_string: %s\n default_string: %s\n arg_string: %s\n show_key: %d\n",
file_string,
default_string,
arg_string,
keyvalue_output);
}
So, this means that your program will act different based on the compiler that you use (gcc/cc). To fix this I (personally) use a loop and a few if's. I doubt ai would do the same (just because a built-in option like getopt(3) exists).
EDIT:
1) Fixed code: `file_string = default_string = arg_string = NULL;`
2) var init.