+ 1

Compiler Error in Solo Learn Code Playground "C" compiler

Here is a simple C program /* Numeric Data Type sizes in bytes */ #include <stdio.h> int main() { printf("\n char is %d bytes", sizeof(char)); printf("\n unsigned char is %d bytes", sizeof(unsigned char)); printf("\n int is %d bytes", sizeof(int)); printf("\n unsigned int is %d bytes", sizeof(unsigned int)); printf("\n short is %d bytes", sizeof(short)); printf("\n unsigned short is %d bytes", sizeof(unsigned short)); printf("\n long is %d bytes", sizeof(long)); printf("\n unsigned long is %d bytes", sizeof(unsigned long)); printf("\n float is %d bytes", sizeof(float)); printf("\n double is %d bytes", sizeof(double)); return 0; } This code compiles correctly, without modification on my local machine. However, when I compile it within Solo Learn's Code Playground it produces a "Compiler Error". I comment out the half of the printf's (doesn't matter which ones) the program compiles correctly. For example: #include <stdio.h> int main() { /* printf("\n char is %d bytes", sizeof(char)); */ printf("\n unsigned char is %d bytes", sizeof(unsigned char)); printf("\n int is %d bytes", sizeof(int)); /* printf("\n unsigned int is %d bytes", sizeof(unsigned int)); */ /* printf("\n short is %d bytes", sizeof(short)); */ printf("\n unsigned short is %d bytes", sizeof(unsigned short)); /* printf("\n long is %d bytes", sizeof(long)); */ printf("\n unsigned long is %d bytes", sizeof(unsigned long)); /* printf("\n float is %d bytes", sizeof(float)); */ printf("\n double is %d bytes", sizeof(double)); return 0; } Anyone have similar problems, or care to verify the bug in the Code Playground compiler?

2nd May 2018, 1:02 AM
Hahn
Hahn - avatar
4 Respostas
+ 4
Well, this was an odd one. Here's a debugging trick.... You've got a lot of warnings, which you can see by commenting half your code lines and adding a nonsense/uncompilable function call like: blah(); // stop compiler and show warnings up to this point ** The format code is complaining about %d expecting an integer while receiving "unsigned long long int". On Linux platforms the proper format code is %llu, on Windows it's something like %I64u. https://stackoverflow.com/questions/2844/how-do-you-printf-an-unsigned-long-long-intthe-format-specifier-for-unsigned-lo This works here: printf("\n char is %I64u bytes", sizeof(char)); printf("\n unsigned char is %I64u bytes", sizeof(unsigned char)); printf("\n int is %I64u bytes", sizeof(int)); ....all of them As for why it crashes with "Compilation error" (when warnings should maybe continue?)... probably too much warning text in the pipe... ? ...but I don't have visibility on that. I'll send a copy to SoloLearn so they can evaluate it.
2nd May 2018, 2:05 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
See Kirk Schafer's reply: Nice one Kirk - your explanation makes perfect sense. Also, thanks for passing it on to the team at SL.
2nd May 2018, 2:10 AM
Hahn
Hahn - avatar
+ 1
It's sent; and thanks for providing the equivalent of the smallest representative sample -- that makes analysis a lot easier.
2nd May 2018, 2:13 AM
Kirk Schafer
Kirk Schafer - avatar
0
maybe the internet connection. since the code playground is server based, it could probably happen.
2nd May 2018, 1:20 AM
Elliot
Elliot - avatar