I'm studying the basic concepts of the C Programming Language on a website called TutorialsPoint. Examples of source code on this website can include a "try it" button that opens up an on-line c programming environment with an on-line c compiler (GNU GCC version 4.7.2). In one example the sizeof() function is demonstrated. Here is the source code.
#include <stdio.h>
#include <limits.h>
int main() {
printf("Storage size for int : %d \n", sizeof(int));
return 0;
}
Link to the lesson: TutorialsPoint - C Data Types
When this program is compiled and executed within the on-line programming environment, the following output is produced:
"Storage size for int : 4"
When I attempt to compile the same code on my computer using the GNU GCC version 5.2.1, I receive the following error message:
gcc sizeofExample.c
sizeofExample.c: In function 'main':
sizeofExample.c:6:10: warning: format '%d' expects argument of type 'int',
but argument 2 has type 'long unsigned int' [-Wformat=]
printf("Storage size for int: %d \n", sizeof(int));
^
Here is my source code, just to be thorough:
#include <stdio.h>
#include <limits.h>
int main()
{
printf("Storage size for int : %d \n", sizeof(int));
return 0;
}
I understand that this error is the result of a data type mismatch between the %d [int data type] and the sizeof(int) [long unsigned int].
Why does my compiler detect a data type mismatch, while TutorialsPoint's on-line compiler does not?