A
Army1987
The following program compiles without errors or warnings with
gcc -ansi -pedantic and works properly.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char *f(char *str1, char *str2)
{
char *res = malloc(strlen(str1)+strlen(str2)+1);
return res ? strcat(strcpy(res, str1), str2) : (exit(1), NULL);
}
int main(void)
{
char a[] = "\nHey man look at me rockin' now\nI'm on the ";
char b[] = "Danny and Lisa";
char c[] = "\nThey take me away from";
char *d = f(f(a, "radio"), f(a, "video"));
char *e = f(d, f(" with ", b));
char *h = f(c, f("\nThe strangest places\nSweet ", b));
char *j = f(e, f(f(h, c), f(h, c)));
return puts(f(f(f(f(d, j), f(j, e)), h), f(d, e)) + 1);
/* No, I don't want to free the memory. If an OS doesn't free it itself, */
/* it doesn't deserve to have it 'till reboot */
}
Instead this one compiles (and does work under Windows if I compile it with
lcc-win32), but under Linux it prints "Segmentation fault (core dumped)" and
returns. Why? I can't see any substantial difference.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char *f(char *str1, char *str2)
{
char *res;
return strcat(strcpy(res=malloc(strlen(str1)+strlen(str2)+1) ? res :
(exit(1), NULL), str1), str2);
}
int main(void)
{
char a[] = "\nHey man look at me rockin' now\nI'm on the ";
char b[] = "Danny and Lisa";
char c[] = "\nThey take me away from";
char *d = f(f(a, "radio"), f(a, "video"));
char *e = f(d, f(" with ", b));
char *h = f(c, f("\nThe strangest places\nSweet ", b));
char *j = f(e, f(f(h, c), f(h, c)));
return puts(f(f(f(f(d, j), f(j, e)), h), f(d, e)) + 1);
}
--
#include <stdio.h>
main()
{
printf("\n\n--\nArmy1987");
}
gcc -ansi -pedantic and works properly.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char *f(char *str1, char *str2)
{
char *res = malloc(strlen(str1)+strlen(str2)+1);
return res ? strcat(strcpy(res, str1), str2) : (exit(1), NULL);
}
int main(void)
{
char a[] = "\nHey man look at me rockin' now\nI'm on the ";
char b[] = "Danny and Lisa";
char c[] = "\nThey take me away from";
char *d = f(f(a, "radio"), f(a, "video"));
char *e = f(d, f(" with ", b));
char *h = f(c, f("\nThe strangest places\nSweet ", b));
char *j = f(e, f(f(h, c), f(h, c)));
return puts(f(f(f(f(d, j), f(j, e)), h), f(d, e)) + 1);
/* No, I don't want to free the memory. If an OS doesn't free it itself, */
/* it doesn't deserve to have it 'till reboot */
}
Instead this one compiles (and does work under Windows if I compile it with
lcc-win32), but under Linux it prints "Segmentation fault (core dumped)" and
returns. Why? I can't see any substantial difference.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char *f(char *str1, char *str2)
{
char *res;
return strcat(strcpy(res=malloc(strlen(str1)+strlen(str2)+1) ? res :
(exit(1), NULL), str1), str2);
}
int main(void)
{
char a[] = "\nHey man look at me rockin' now\nI'm on the ";
char b[] = "Danny and Lisa";
char c[] = "\nThey take me away from";
char *d = f(f(a, "radio"), f(a, "video"));
char *e = f(d, f(" with ", b));
char *h = f(c, f("\nThe strangest places\nSweet ", b));
char *j = f(e, f(f(h, c), f(h, c)));
return puts(f(f(f(f(d, j), f(j, e)), h), f(d, e)) + 1);
}
--
#include <stdio.h>
main()
{
printf("\n\n--\nArmy1987");
}