Author Topic: Set to ANSI C standard?  (Read 13321 times)

Offline drewvoros

  • Single posting newcomer
  • *
  • Posts: 9
Set to ANSI C standard?
« on: January 29, 2015, 05:13:48 pm »
Hello knowledgeable forum members,

I'm starting an intro to C course this semester and am required to use a compiler that is ANSI C standard.

The Prof. requires ANSI C standard and requests the class use C-Free. However I've used Code::Blocks before and much prefer it (one thing being the helpfulness of how it completes common syntax and other useful tidbits like automatically inserting closing brackets... both of which C-Free does not do)

So I will be using the GNU GCC compiler but how do I make sure it is ANSI C standard?
I don't know much about the intricacies of compilers but know from my previous experience with C++ (a previous intro class taken a while back) that the GNU GCC worked great.

Just need to really make sure that what I'm using is ANSI C standard. Otherwise it's not allowed for the course  :(

Note: I'm told C++ compilers work with C code. I don't want to run into the problem of thinking my programs are running fine because I'm not compiling in strict ANSI C standard and then when I turn in the programs don't run on the Prof.'s computer after he complies in ANSI C standard.

Any instruction would be great!
« Last Edit: February 05, 2015, 04:04:42 pm by drewvoros »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Set to ANSI C standard?
« Reply #1 on: January 29, 2015, 05:29:39 pm »
--ansi option is the common option; please confirm this is the right option for your Compiler.
Note: CB is an IDE; it is NOT a compiler.

Look for the option under Compiler Setting if NOT there add under Compiler other options.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Set to ANSI C standard?
« Reply #2 on: January 29, 2015, 05:40:02 pm »
How nice of your prof to use a word like "ANSI" which is not at all ambiguous, except for allowing for at least 4 different language versions...

There's at least c89, c90, c99, and c11 to choose from, all of which are ISO/IEC/ANSI.

You can select "mostly" ANSI C90 mode in GCC with --ansi, this is equivalent to --std=c90. If a newer version (like e.g. c99) is allowable, use --std=c99 instead.

It is a good idea to add -pedantic-errors to make the compiler behave more strictly, since it still allows a couple of GNU extensions even in ANSI mode otherwise.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline drewvoros

  • Single posting newcomer
  • *
  • Posts: 9
Re: Set to ANSI C standard?
« Reply #3 on: January 29, 2015, 06:12:32 pm »
Hi Tim,
I understand CB is an IDE and not compiler. Still not sure about confirming that I will be in fact compiling in strict "ANSI C standard".

Hi Thomas,
Wish I knew more but all my syllabus says is must be strict "ANSI C standard... recommend you all use what I will be using C-Free"

Still not sure where to set. I'm assuming under Project > Build Options > ... then I get the attached image. What do I need to check to make sure?
« Last Edit: January 29, 2015, 06:15:26 pm by drewvoros »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Set to ANSI C standard?
« Reply #4 on: January 29, 2015, 06:32:07 pm »
Hi Tim,
I understand CB is an IDE and not compiler. Still not sure about confirming that I will be in fact compiling in strict "ANSI C standard".
No you are not, because otherwise you wouldn't ask this question  ;)

recommend you all use what I will be using C-Free"
As far as i can see C-Free is also only a IDE and not a compiler (and also not shipped with one), so how will your prof say that it is 100% ANSI C?

Quote
Still not sure where to set. I'm assuming under Project > Build Options > ... then I get the attached image. What do I need to check to make sure?
This is the right place. You need the -ansi option

[Edit:] or the options Thomas mentioned...  but we don't know, because your prof is unclear in this point (C90, C99, C11 -> All ANSI standards)
« Last Edit: January 29, 2015, 06:35:25 pm by BlueHazzard »

Offline drewvoros

  • Single posting newcomer
  • *
  • Posts: 9
Re: Set to ANSI C standard?
« Reply #5 on: January 29, 2015, 06:42:10 pm »
Thanks for the reply BlueHazzard,

I think I need to find out for sure from the prof. about the distinction of C90, C99, C11 standards. I'm hoping he knows because in his syllabus he definitely refers to C-Free as the "compiler" he will be using to grade :o

I will post back when I hear from him later this evening. Hopefully then I can clarify what I really need. Thanks for the help so far everyone!

Offline drewvoros

  • Single posting newcomer
  • *
  • Posts: 9
Re: Set to ANSI C standard?
« Reply #6 on: January 29, 2015, 07:19:45 pm »
Oh by the way when I downloaded the recommended C-Free 4.0 the default compiler was mingw2.95
I'm assuming that is what the prof will be using because no instructions to change the compiler settings were given. Don't know if this helps any with more info.

Still waiting to hear back about the C90, C99, C11 distinction from the prof. Will update later tonight.

Offline drewvoros

  • Single posting newcomer
  • *
  • Posts: 9
Re: Set to ANSI C standard?
« Reply #7 on: January 30, 2015, 03:52:03 am »
So I heard back from my prof and I'm pretty sure he doesn't know anything about compilers because he responded with "I cannot verify anything about a product I never used" even after I listed all versions of the ANSI standards we've talked about.  >:(

So yes frustrating. But I know C-Free's  default compiler is MinGW 2.95. Any advice how to set the GNU GCC to behave similarly? Or any other suggestions?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Set to ANSI C standard?
« Reply #8 on: January 30, 2015, 01:19:05 pm »
Or any other suggestions?

Install the exact compiler as being used by your stupid professor is the only true way.

But, 2.95 is so old it likely will NOT run on your computer.

Try C90 on your computer for development then test the code on another computer able to run 2.95.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Set to ANSI C standard?
« Reply #9 on: January 30, 2015, 02:01:29 pm »
default compiler was mingw2.95  8) 8) 8)

Still waiting to hear back about the C90, C99, C11 distinction from the prof. Will update later tonight.
Um... yeah, right. MinGW-GCC 2.95. That's... a 14 year old MinGW build which uses a pretty shitty 16 year old version of GCC.  ;D

No need to worry about C99 or C11 then, they're out of the question with that compiler. It's reassuring when the teacher recommends one of the worst compilers in history...

Anyway, you will be using the --ansi -pedantic-errors command line options with that compiler. I don't know where you would put it in Free-C (which by the way seems to cost money, as opposed to "free"?), but presumably there are some kind of "project options" or global "compiler options" there just in the same way as in Code::Blocks.

I would recommend putting it directly in the compiler's options since that way you cannot accidentially forget doing so (which is bound to happen if you add it manually to each and every project).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline drewvoros

  • Single posting newcomer
  • *
  • Posts: 9
Re: Set to ANSI C standard?
« Reply #10 on: January 31, 2015, 04:25:59 am »
Thanks Tim and Thomas for the response!

Yea this is unfortunate that my prof is suggesting such an outdated compiler. Or least he is suggesting an inferior IDE and has not instructed anyone to update the version of MinGW 2.95 that comes with it standard.   ???

I think I'll stick with CB and the GNU GCC to write my code and test and finally before submission I'll do one run through through C-Free's MinGW 2.95 compiler (oh Thomas c-free is free for the 4.0 version). I'll mark off the suggested compiler build options that you suggested (in CB) too, Thomas.

This way I'll still be able to use CB and just the other inferior IDE for a double check.

I'm going to ask the prof if he would suggest us to update the version of MinGW in his IDE of choice. When I hear back perhaps I'll need a bit more help to check off new boxes?

I'll post back when I hear. If not I'll mark the thread solved. Thanks so much with the help!



Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Set to ANSI C standard?
« Reply #11 on: January 31, 2015, 10:03:06 am »
Be aware!:
two compilers with different version on one system is not a good idea. Especially mingw, because of his hard coded paths (i don't know if they are fixed now)... I woul recommend you to use one compiler in a vm, or at least keep your PATH in sync with the compiler you are using (delete the other compiler from the PATH variable)

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Set to ANSI C standard?
« Reply #12 on: January 31, 2015, 10:40:41 am »
Be aware!:
two compilers with different version on one system is not a good idea. Especially mingw, because of his hard coded paths (i don't know if they are fixed now)... I woul recommend you to use one compiler in a vm, or at least keep your PATH in sync with the compiler you are using (delete the other compiler from the PATH variable)
And do not install any of these compilers in "\MinGW" on any disk, at  least not if you want/need to install multiple versions on one system.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Set to ANSI C standard?
« Reply #13 on: January 31, 2015, 02:35:39 pm »
Be aware!:
two compilers with different version on one system is not a good idea. Especially mingw, because of his hard coded paths (i don't know if they are fixed now)... I woul recommend you to use one compiler in a vm, or at least keep your PATH in sync with the compiler you are using (delete the other compiler from the PATH variable)
And do not install any of these compilers in "\MinGW" on any disk, at  least not if you want/need to install multiple versions on one system.
That works pretty well if you have recent versions (and reasonable builds).

I have both MinGW (4.8.1) and MSYS installed on C:\, LLVM (the Visual Studio overload) in C:\Programs (x86)\LLVM, and
mingw-w64-4.9.2-w32, mingw-w64-4.9.2-w64, tdm-4.9.2-w32, and tdm-4.9.2-w64 side by side in D:\buildtools.

Code::Blocks works with any of these.

Only issues are that
a) LLVM seriously sucks because it is incapable of exception handling and borrows that functionality with some obscure hack that I do not quite understand fully from the first compiler install that it finds in PATH. Which happens to be... not precisely a rock solid solution especially if you regularly update compilers and have multilib compilers among your set of compilers. In particular, if you use exceptions with 64bit code on my machine, LLVM will borrow TDM's multilib version to throw SJLJ 32-bit exceptions which fails with missing symbols.
b) The compiler management in Code::Blocks isn't really meant to be used with half a dozen versions of the same compiler at the same time and divine the correct version for every case without user interaction. It certainly works as designed, but not always as wanted (without manually changing project options). Admittedly, it would be hard to implement something much better, too.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline drewvoros

  • Single posting newcomer
  • *
  • Posts: 9
Re: Set to ANSI C standard?
« Reply #14 on: February 05, 2015, 02:08:01 am »
Heard back from Prof. he is indeed using mingw2.95

So I think I have my global compiler setting flags ticked for that now in CB, Thanks Thomas!

Oh sorry about the confusion, I don't plan on installing mingw2.95 also into CB, what I meant is that I will install both IDEs and be using CB and the GNU GCC to write source and compile and test.... then right upon submission I'll open the source in the other IDE and test with its mingw compiler. 2 compilers but in 2 different environments. (At least I think this is the best option for me right now if I want to use CB but also want to make sure compiling on my Prof's machine goes as expected)

Thanks everyone for the helpful guidance. I'll mark the Thread Solved.
« Last Edit: February 05, 2015, 02:10:45 am by drewvoros »