Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I found an interesting stuff:

when programming using Code::Blocks, the following program(C) runs smoothly:

XML
#include <stdio.h>
#include <stdlib.h>

int power(int m, int n);

main()
{
    printf("This is a program for exponientiation\n");
    int i;
    ...


but, when i copied this piece of code into VC2010, its debugger detected several errors and i have to revise it into the following form to make it running smoothly in VC2010:

XML
#include <stdio.h>
#include <stdlib.h>

int power(int m, int n);

main()
{

    int i;
     printf("This is a program for exponientiation\n");
     ...


and this kind of form (where printf() has been placed after the definition of variables) works also okay in Code::Blocks, who could tell me why this happened?
Does the Code::Blocks enjoys a better fault tolerance or, does the VC2010 requires more strictly about the code form?


PS: a friend told me that the first form is more likely a C++ one, perhaps CodeBlocks is less sensitive to the difference between C and C++?...
Posted
Updated 9-Apr-11 3:38am
v2
Comments
Slacker007 9-Apr-11 8:05am    
If you want me to think that you are stupid, then I will. If you are here looking for a quick answer and that's it then stay stupid. However, if you feel like sticking around then change your screen name. Something tells me that you are not stupid. Good luck. :)
StupidSteve 9-Apr-11 8:26am    
Oops...i think i have to tell you that in China there is something works like a "reverse magic" when naming something, i wanna be smart so i picked this funny cybername:)
Nevermind~ and i just wonder which is better for a newcomer to C just like me---the CodeBlocks or the VC? do you have an advice?
Albert Holguin 9-Apr-11 14:22pm    
i actually do think its funny... :D
StupidSteve 9-Apr-11 8:46am    
BTW, could you answer my question above?
what on earth leads to this kind of difference between CodeBlocks and VC in debugging a program?
which piece of my code is more acceptable in form?

THX alot
Slacker007 9-Apr-11 8:48am    
Unfortunately I am not a C programmer. We have a lot of great C programmers here who will be more than glad to help you. It is the weekend though and they may not get to your question until Monday. Cheers.

1 solution

The first form is C++ not C, so if you add it to VC2010 as a C program (with file extension .c) it will give errors. If you save the same code as C++ (give the file a .cpp extension) it should compile OK. These are just the rules of the languages, and I can only presume that Code::Blocks (whatever that is) does not enforce the rules correctly.
 
Share this answer
 
Comments
Albert Holguin 9-Apr-11 14:20pm    
if code blocks accepts the statement, then they're not following C standards, in studio there's usually also an option to compile as strict C, i'd imagine code blocks should have a similar option (if it doesn't, then I wouldn't recommend using it for C since you won't learn the language correctly)
Richard MacCutchan 9-Apr-11 14:25pm    
That's what I said.
Albert Holguin 9-Apr-11 14:28pm    
no, you said it distinguishes from the file extension, that's not the only way, you can force it to use C... then i suggested that he look for the option in codeblocks... anyway, i added the comment as additional info, not to dispute what you're saying
Albert Holguin 9-Apr-11 14:36pm    
AND... i upvoted your solution... you're welcome.
StupidSteve 9-Apr-11 23:01pm    
You are right, I think what I was firstly doing yesterday with CodeBlocks was not so "enforced" enough with C's rules. And I changed it into (.cpp) and it turned to be okay.

But in the CodeBlocks (for more info you may check its wikipedia website http://en.wikipedia.org/wiki/Codeblocks), I remembered clearly that I built a console project and add a C file (.c) as a headfile to this project. Maybe there is some other method to force Codeblocks to compile in C and I will try to find it.

I think VC is better for a beginner, for it enforces the rules. But i really like CodeBlocks--- its faster.

Thank you very much for your help!~

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900