Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chas...
#3: Post edited
- When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chasing down the bug but failed.
- Then upon viewing their code, I notice that the code should never have "compiled cleanly" - there were warnings, but the beginner didn't read them. If they had done so, it would have saved them a lot of time.
Not reading warnings could in turn be caused by the IDE used hiding away warnings in some hard-to-spot window, or because they picked some "compile & run" option, or simply because they weren't paying attention.- Or possibly because they think that warnings mean "here's a little cosmetic issue that you should fix when you have time", and not "here is a severe bug that will likely prevent your program from working as expected" which is closer to the truth most of the time.
Unfortunately, a compiler isn't _required_ to give an error upon C language violations. A "diagnostic message" is sufficient, as discussed at [What must a C compiler do when it finds an error?](https://software.codidact.com/posts/277340).- **Are there any recommended compiler options beginners should use to avoid accidentally running programs with errors already spotted by the compiler?**
- Mostly interested in the "gcc-like" mainstream compilers: gcc, clang and icc, which have compatible command-line options.
- When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chasing down the bug but failed.
- Then upon viewing their code, I notice that the code should never have "compiled cleanly" - there were warnings, but the beginner didn't read them. If they had done so, it would have saved them a lot of time.
- Not reading warnings could in turn be caused by the IDE used, which is hiding away warnings in some hard-to-spot window, or because they picked some "compile & run" option, or simply because they weren't paying attention.
- Or possibly because they think that warnings mean "here's a little cosmetic issue that you should fix when you have time", and not "here is a severe bug that will likely prevent your program from working as expected" which is closer to the truth most of the time.
- Unfortunately, a compiler isn't _required_ to give an error upon C language violations. A "diagnostic message" is sufficient, as discussed at [What must a C compiler do when it finds an error?](https://software.codidact.com/posts/277340)
- **Are there any recommended compiler options beginners should use to avoid accidentally running programs with errors already spotted by the compiler?**
- Mostly interested in the "gcc-like" mainstream compilers: gcc, clang and icc, which have compatible command-line options.
#2: Post edited
- When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chasing down the bug but failed.
Then upon viewing their code, I notice that the code should never have "compiled cleanly" - there were warnings, but the beginner didn't read them.- Not reading warnings could in turn be caused by the IDE used hiding away warnings in some hard-to-spot window, or because they picked some "compile & run" option, or simply because they weren't paying attention.
- Or possibly because they think that warnings mean "here's a little cosmetic issue that you should fix when you have time", and not "here is a severe bug that will likely prevent your program from working as expected" which is closer to the truth most of the time.
- Unfortunately, a compiler isn't _required_ to give an error upon C language violations. A "diagnostic message" is sufficient, as discussed at [What must a C compiler do when it finds an error?](https://software.codidact.com/posts/277340).
- **Are there any recommended compiler options beginners should use to avoid accidentally running programs with errors already spotted by the compiler?**
- Mostly interested in the "gcc-like" mainstream compilers: gcc, clang and icc, which have compatible command-line options.
- When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chasing down the bug but failed.
- Then upon viewing their code, I notice that the code should never have "compiled cleanly" - there were warnings, but the beginner didn't read them. If they had done so, it would have saved them a lot of time.
- Not reading warnings could in turn be caused by the IDE used hiding away warnings in some hard-to-spot window, or because they picked some "compile & run" option, or simply because they weren't paying attention.
- Or possibly because they think that warnings mean "here's a little cosmetic issue that you should fix when you have time", and not "here is a severe bug that will likely prevent your program from working as expected" which is closer to the truth most of the time.
- Unfortunately, a compiler isn't _required_ to give an error upon C language violations. A "diagnostic message" is sufficient, as discussed at [What must a C compiler do when it finds an error?](https://software.codidact.com/posts/277340).
- **Are there any recommended compiler options beginners should use to avoid accidentally running programs with errors already spotted by the compiler?**
- Mostly interested in the "gcc-like" mainstream compilers: gcc, clang and icc, which have compatible command-line options.
#1: Initial revision
What compiler options are recommended for beginners learning C?
When reading questions about C programming from beginners, I very often see them describing peculiar run-time errors and crashes, segmentation faults and similar. They have spent a lot of time chasing down the bug but failed. Then upon viewing their code, I notice that the code should never have "compiled cleanly" - there were warnings, but the beginner didn't read them. Not reading warnings could in turn be caused by the IDE used hiding away warnings in some hard-to-spot window, or because they picked some "compile & run" option, or simply because they weren't paying attention. Or possibly because they think that warnings mean "here's a little cosmetic issue that you should fix when you have time", and not "here is a severe bug that will likely prevent your program from working as expected" which is closer to the truth most of the time. Unfortunately, a compiler isn't _required_ to give an error upon C language violations. A "diagnostic message" is sufficient, as discussed at [What must a C compiler do when it finds an error?](https://software.codidact.com/posts/277340). **Are there any recommended compiler options beginners should use to avoid accidentally running programs with errors already spotted by the compiler?** Mostly interested in the "gcc-like" mainstream compilers: gcc, clang and icc, which have compatible command-line options.