Author Topic: How to build in C?  (Read 3763 times)

Offline purestr999

  • Single posting newcomer
  • *
  • Posts: 2
How to build in C?
« on: November 24, 2010, 12:45:28 pm »
I have looked in all the settings for hours for a way to fix this but I can't find an answer. I am new to programming so please post easy instructions if you can.
If I use the project wizard and make a C project, then everything works fine.
But if I use the file wizard and make a C file, or if I make a blank file and name it file.c, then when I try to compile programs, it compiles in C++. I do have a .c file from a few weeks ago that does compile in C, but if I copy it for example, its new copy won't.

For example: (somebody gave me this on another forum)
Code
#include<stdio.h>
int main ( ) {
#ifdef __cplusplus
  printf("Compiled as C++\n");
#else
  printf("Compiled as C\n");
#endif
  return 0;
}
outputs "Compiled as C++"

and:
Code
#include <stdio.h>
#include <stdlib.h>

enum country {italy, america, france, brazil, england, newzealand, nepal, switzerland, canada, australia};
typedef enum country country;

int main(void)
{
    country tmpcountry;

    for(tmpcountry = 0; tmpcountry <= 9; ++tmpcountry)
        printf("%d\n", tmpcountry);
    return 0;
}

has compile errors (because C++ doesn't let you do arithmetic with enum, but C does let you.



I can't make all my programs in projects for school reasons. Can anyone tell me simply how to fix this? Thanks!

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: How to build in C?
« Reply #1 on: November 24, 2010, 02:26:55 pm »
Check if your c-compiler is set correctly ("Setup -> Compiler and debugger... -> GNU GCC Compiler -> Toolchain executables -> C compiler").

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: How to build in C?
« Reply #2 on: November 24, 2010, 03:53:00 pm »
Remember files with ".c" extension are by default treated as C files under Code::Blocks.
Any other extension is treated as C++ file.

Turning on FULL compiler logging will help determine the real problem.

http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F

Tim S.
« Last Edit: November 24, 2010, 04:00:05 pm by stahta01 »
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: How to build in C?
« Reply #3 on: November 24, 2010, 06:08:35 pm »
purestr999: This is a known problem with 8.02, it is fixed in 10.05 and newer, so please update CB and recreate your project.
If you want to fix the project, right click the .c file -> properties -> advanced, then change the type from CC to C or something like that.
(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 purestr999

  • Single posting newcomer
  • *
  • Posts: 2
Re: How to build in C?
« Reply #4 on: November 25, 2010, 08:56:52 pm »
Thanks for the help everyone, especially oBFusCATed, I downloaded codeblocks from my universities site so I guess it was a couple years old >.> I installed the updated codeblocks and everything compiles fine now :)

Offline Joe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: How to build in C?
« Reply #5 on: December 02, 2010, 01:19:46 am »
Hi purestr999,

Sounds like your problem was solved by oBFusCATed. Could you update the title of your issue with - [solved], so other people with a similar problem will know there is an answer in this post.
Joe Long
WinXP Home/SP3
Code::Blocks/10.05
Borland 5.5/SP2
C++ Student