Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C VC10.0
I found an interesting stuff:
 
when programming using Code::Blocks, the following program(C) runs smoothly:
 
#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:
 
#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 9-Apr-11 3:02am
Edited 9-Apr-11 4:38am
v2
Comments
Slacker007 at 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 at 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 at 9-Apr-11 14:22pm
   
i actually do think its funny... :D
StupidSteve at 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 at 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.
StupidSteve at 9-Apr-11 8:54am
   
okay i know it~ Thanks alot~
have a nice weekend:)
Albert Holguin at 9-Apr-11 14:21pm
   
hey steve, look at my comment in richard's answer...
StupidSteve at 9-Apr-11 23:08pm
   
Hi!~ Albert!
I find that there is an option of choosing "which compiler you would like to use?" and I chose "GNU GCC" compiler, is this the option you mean?
Albert Holguin at 10-Apr-11 2:42am
   
that would be correct assuming there's an option that has "GNU G++", but since people call the GNU compiler gcc generically, i'm not sure if that means forcing to C.. you can try it and see if it works as expected

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Albert Holguin at 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 at 9-Apr-11 14:25pm
   
That's what I said.
Albert Holguin at 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 at 9-Apr-11 14:36pm
   
AND... i upvoted your solution... you're welcome.
StupidSteve at 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!~
Albert Holguin at 10-Apr-11 15:52pm
   
curious, what's faster about CodeBlocks?
StupidSteve at 10-Apr-11 20:43pm
   
it complies and runs the same program faster than VC, nevertheless that it's coding is more intelligent than VC-- it could automatically fill in some characters so that you don't have to type again~have a try~
Albert Holguin at 10-Apr-11 21:04pm
   
i've been coding in vs for a long time, so i'm used to the good, the bad, and the ugly... lol... i actually like it...
Richard MacCutchan at 11-Apr-11 4:44am
   
I doubt that the speed is any different if you use the same compiler. The IDE may have some extra features but the compiled code will be the same if you use the same compiler. If you are talking of the difference between VC compiler and GCC then there may be some speed differences but you would need to run a lot of tests to see the benefit.
StupidSteve at 11-Apr-11 5:49am
   
O, i realized that i am using the VC complier in VC2010 but the GCC compiler in CD, does the VC complier has more useful features that makes its speed lower?
 
BTW, I really love using VC to debug--- it works much better when debugging a program.
Richard MacCutchan at 11-Apr-11 9:04am
   
No idea, I have never done any speed tests. All I was saying is that it is unlikely that you would be able to tell without running a lot of tests using different program types. At the end of the day it is largely irrelevant since most people just stick with the product they like or feel comfortable with. I have used GCC in Unix/Linux environments and found its features perfectly suitable for the work I was doing; that does not make it better or worse than any other product.
 
StupidSteve at 11-Apr-11 10:17am
   
Yes you are right:) thank you very much for your reply and help:)
Albert Holguin at 11-Apr-11 9:34am
   
Find what you like and work with that... there is likely a difference in speed but you would only notice it with very large programs... the debugger in studio is one of the best i've ever worked with
Richard MacCutchan at 11-Apr-11 9:59am
   
Dear Albert, thanks for all this feedback but I really think it would be better if you responded to StupidSteve.
Albert Holguin at 11-Apr-11 10:21am
   
i thought i did, the alignment of the page was right where it breaks to the second page when i made this last comment, apologies.
Richard MacCutchan at 11-Apr-11 12:14pm
   
No problem, I've done it myself from time to time.
Richard MacCutchan at 11-Apr-11 4:41am
   
It is not faster. Code::Blocks is not a compiler, but an IDE and if you use the same underlying compiler (e.g. Microsoft's C compiler) it's not likely that it will operate at anything but the same speed. It's possible that one of the other compilers that is used is technically faster but I doubt that any human would notice the difference, unless the build process takes a very long time.
StupidSteve at 11-Apr-11 5:39am
   
Now i also doubt that VC2010 has more "visual effect" and caused the relatively low running speed, I am using CD 10.05 and VC2010professional at the same time--- believe that I can sense the different of speed---- maybe the difference has nothing to do with the compiler-- but its because of the different software platform.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 275
2 BillWoodruff 260
3 Shweta N Mishra 244
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 9 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100