Skip to content

Instantly share code, notes, and snippets.

@hkuno9000
Created April 15, 2015 07:57
Show Gist options
  • Save hkuno9000/57edb60ab0daa21f9ef9 to your computer and use it in GitHub Desktop.
Save hkuno9000/57edb60ab0daa21f9ef9 to your computer and use it in GitHub Desktop.
TESTCODE: NULL is safe as a argument of printf("%s")
#include <stdio.h>
#include <stdlib.h>
int main()
{
char buf[200];
puts("*** test printf NULL");
printf( "printf :%s,%S,%ws\n", NULL, NULL, NULL);
#ifdef _MSC_VER
sprintf_s(buf, "sprintf_s:%s,%S,%ws\n", NULL, NULL, NULL); puts(buf);
#endif
return 0;
}
/*
RESULT: VC9(vs2008) on Windows7
*** test printf NULL
printf :(null),(null),(null)
sprintf_s:(null),(null),(null)
RESULT: gcc4.8.3 on cygwin
*** test printf NULL
printf :(null),(null),ws
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment