Author Topic: Forcing ANSI C standard only.  (Read 24542 times)

Offline caveman_1990

  • Single posting newcomer
  • *
  • Posts: 2
Forcing ANSI C standard only.
« on: September 06, 2010, 06:45:29 am »
Hey,

I am currently studying C language at university and the lecture requires us to use "ANSI C standard" for our coding or else we will get a FAIL so can anyone please help me on how to setup code::blocks to use only ANSI C standard.

Thanks.

kevin

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: Forcing ANSI C standard only.
« Reply #1 on: September 06, 2010, 07:20:36 am »
Compile your code with the -ansi option, setup your compiler / project's compiler options accordingly.

However, still you should know what you are doing and what ANSI C actually means.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline caveman_1990

  • Single posting newcomer
  • *
  • Posts: 2
Re: Forcing ANSI C standard only.
« Reply #2 on: September 07, 2010, 03:13:12 am »
Ok thanks for the help.

Offline wrath

  • Single posting newcomer
  • *
  • Posts: 2
Re: Forcing ANSI C standard only.
« Reply #3 on: August 12, 2011, 09:33:36 am »
Hey,

I am currently studying C language at university and the lecture requires us to use "ANSI C standard" for our coding or else we will get a FAIL so can anyone please help me on how to setup code::blocks to use only ANSI C standard.

Thanks.

kevin

Hey kevin did you get to change codeblock to use "ANSI C standard"? cause thats what i need at the moment
-I once tried thinking for an entire day, but I found it less valuable than one moment of study-

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Forcing ANSI C standard only.
« Reply #4 on: August 12, 2011, 11:02:23 am »
Project -> Build options -> Compiler options -> Ansi bla bla...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable
Re: Forcing ANSI C standard only.
« Reply #5 on: August 12, 2011, 12:22:28 pm »
Assuming that you use the GNU GCC Compiler:
For a supportive ansi C learning environment you will need to tick the following compiler flags in menu [Project]->[Build Options]:

- In C mode, support all ISO C programs...  [-ansi]
- Enable all compiler warnings... [-Wall]
- Enable warnings demanded by strict ISO C and... [-pedantic]

Never forget to create a project with these flags for every program that you build, even when there is only a single source code file in the project.

Alternatively:
If you always want this setup without having to set the flags for every new project, tick the same flags in the global compiler settings instead:
Go to menu [Settings]->[Compiler and debugger], then with the GNU GCC compiler selected, tick those same flags under the "Compiler Flags" tab.

@ Morten
Most C educational environments now use the ISO C99 standards instead of ansi.
The GCC flag -std=c99 is not available in the Codeblocks project build options and would be needed for those cases instead of -ansi.

I think that -std=c99 is worth adding to the compiler flag options for GCC and the equivalent for other compilers.
« Last Edit: August 12, 2011, 01:50:17 pm by codeur »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Forcing ANSI C standard only.
« Reply #6 on: August 12, 2011, 02:58:01 pm »
I disagree, they should also learn where to put the "other options" :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable
Re: Forcing ANSI C standard only.
« Reply #7 on: August 13, 2011, 01:39:21 am »
I disagree, they should also learn where to put the "other options" :)
That colleague of mine (C teacher) also thinks that they should learn to compile and link from the command line and learn to edit with vi.  :?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Forcing ANSI C standard only.
« Reply #8 on: August 13, 2011, 01:58:06 am »
He is wrong only about the last part :)
The compile and link part is really needed:)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable
Re: Forcing ANSI C standard only.
« Reply #9 on: August 13, 2011, 03:11:51 am »
There is some truth in that oBFusCATed, but that teacher is not developing an IDE, you are.

However the beauty of open source is shown in action here. If some people think that a particular compiler flag is important for C programmers and an IDE developer does not want to make the flag available up-front in the IDE for whatever reason, these people can always add that flag, then distribute the modified IDE and the associated patch.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: Forcing ANSI C standard only.
« Reply #10 on: August 13, 2011, 06:40:30 am »
@ Morten
Most C educational environments now use the ISO C99 standards instead of ansi.
The GCC flag -std=c99 is not available in the Codeblocks project build options and would be needed for those cases instead of -ansi.

I think that -std=c99 is worth adding to the compiler flag options for GCC and the equivalent for other compilers.
If you come up with a patch that would be nice. I am rather busy these days... but practically it should be a one-liner for each relevant compiler. It would be nice if you take other -std=XXX options into consideration, too... I don't know what else is available and makes sense.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline codeur

  • Multiple posting newcomer
  • *
  • Posts: 113
    • Code::Blocks EDU-Portable
Re: Forcing ANSI C standard only.
« Reply #11 on: August 29, 2011, 04:37:36 am »
@ Morten,
Patch 003204 now on berliOS adds option flag -std=c99 to the GCC compilers GNUARM, GNUAVR, GNUMSP430, GNUPOWERPC, GNUTRICORE, MINGW.
This was overdue for C standards, but no other -std=XXX option makes sense at this point for C. The contemporary C++ standards are already well supported.

nickwelhar

  • Guest
Re: Forcing ANSI C standard only.
« Reply #12 on: April 03, 2015, 10:23:26 am »
What is ANSI ?
 
ANSI (American National Standards Institute) codes are standardized numeric or alphabetic codes issued by the American National Standards Institute to ensure uniform identification of geographic entities through all federal government agencies. It has served as coordinator of the U.S. private sector, voluntary standardization system for more than 90 years. This is essentially an extension of the ASCII character set in that it includes all the ASCII characters with an additional 128 character codes. ASCII just defines a 7 bit code page with 128 symbols. ANSI extends this to 8 bit and there are several different code pages for the symbols 128 to 255. More about ANSI

Nick

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: Forcing ANSI C standard only.
« Reply #13 on: April 03, 2015, 12:19:30 pm »
Nick
Are you a spammer? This is a thread dated back 2011. If you continue to make such non-sense posts you'll be banned.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ