Testing basic C code in a separate IDE?

gregulator

Senior member
Apr 23, 2000
631
4
81
I constantly find myself running into bits and pieces of code that I want to test for basic functionality, but I am in an embedded IDE without a simulator/console level debugger, or want to just look at a basic procedure. Does anyone have a good workflow for this? Should I just keep open a separate IDE and plug in these pieces and output to the console?

Example: I am manipulating bytes in and out of an array, and want to make sure they are in the right order. I just want to test this little piece of code without running it on hardware, or firing up a simulator.

I am on Win7 platform. Is there a super light IDE I can use? Thanks!
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Can you at least compile (would think so...)? Could check the output. It's not ideal, but would work.

It all depends on what you're trying to analyze.

If you're in the windows environment, I like DEV C++ (www.bloodshed.net) but different compilers can follow slightly different rules.

For example:

for(int i = 1; i < 10; i++)

Is fine in DEV C++

But in VS, you can't declare a variable in the for statement, thus it would be:

int i;
for(i = 1; i < 10; i++)

So the rules might be slightly different between the two environments.
 

smackababy

Lifer
Oct 30, 2008
27,024
79
86
But in VS, you can't declare a variable in the for statement, thus it would be:

int i;
for(i = 1; i < 10; i++)

So the rules might be slightly different between the two environments.

Are you sure about this? It has been awhile since I've used C++ extensively, but I don't recall ever having to do that. I could just be getting forgetful though.
 

Merad

Platinum Member
May 31, 2010
2,586
19
81
Can you at least compile (would think so...)? Could check the output. It's not ideal, but would work.

It all depends on what you're trying to analyze.

If you're in the windows environment, I like DEV C++ (www.bloodshed.net) but different compilers can follow slightly different rules.

For example:

for(int i = 1; i < 10; i++)

Is fine in DEV C++

But in VS, you can't declare a variable in the for statement, thus it would be:

int i;
for(i = 1; i < 10; i++)

So the rules might be slightly different between the two environments.

First off - don't use Dev C++. Just don't. Pretty please?

Second - the compilers just don't randomly have "different rules". MSVC implements the C89 standard, which requires variables to be declared at the beginning of a scope. Dev-C++ includes an obsolete version of the mingw compiler. Mingw is based on the *nix GNU Compiler Collection (gcc) which implements the more modern C99 standard allowing variables to be declared anywhere in the body of a function.

If OP's code does not work with MSVC he/she would be much better off using a modern version of mingw or cygwin.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Can you at least compile (would think so...)? Could check the output. It's not ideal, but would work.

It all depends on what you're trying to analyze.

If you're in the windows environment, I like DEV C++ (www.bloodshed.net) but different compilers can follow slightly different rules.

For example:

for(int i = 1; i < 10; i++)

Is fine in DEV C++

But in VS, you can't declare a variable in the for statement, thus it would be:

int i;
for(i = 1; i < 10; i++)

So the rules might be slightly different between the two environments.

I have done such in all VS up through '12.

It is a legal feature of the language.

Please post a code snippet of where this failed.
 

Merad

Platinum Member
May 31, 2010
2,586
19
81
I have done such in all VS up through '12.

It is a legal feature of the language.

Please post a code snippet of where this failed.

Compiled as C++ it will of course work fine. Compiled as C it will fail because MSVC only implements C89.

Edit:
Code:
int main(int argc, char** argv)
{
  for (int i = 0; i < 10; ++i)
  {
  }
  return 0;
}

Compiling the above as C, MSVC10 sez:

1>d:\programming\projects\derp\derp\derp.c(3): error C2143: syntax error : missing ';' before 'type'
1>d:\programming\projects\derp\derp\derp.c(3): error C2143: syntax error : missing ';' before 'type'
1>d:\programming\projects\derp\derp\derp.c(3): error C2143: syntax error : missing ')' before 'type'
1>d:\programming\projects\derp\derp\derp.c(3): error C2143: syntax error : missing ';' before 'type'
1>d:\programming\projects\derp\derp\derp.c(3): error C2065: 'i' : undeclared identifier
1>d:\programming\projects\derp\derp\derp.c(3): warning C4552: '<' : operator has no effect; expected operator with side-effect
1>d:\programming\projects\derp\derp\derp.c(3): error C2059: syntax error : ')'
1>d:\programming\projects\derp\derp\derp.c(4): error C2065: 'i' : undeclared identifier
1>d:\programming\projects\derp\derp\derp.c(4): error C2143: syntax error : missing ';' before '{'
 
Last edited:

Leros

Lifer
Jul 11, 2004
21,867
7
81
There's no reason you can't have your project open in two IDEs at once. You can open your project in another IDE like Visual Studio. You can then write small test programs that call into your project's code and run them from within that other IDE.
 

cytg111

Lifer
Mar 17, 2008
26,410
15,777
136
First off - don't use Dev C++. Just don't. Pretty please?

Second - the compilers just don't randomly have "different rules". MSVC implements the C89 standard, which requires variables to be declared at the beginning of a scope. Dev-C++ includes an obsolete version of the mingw compiler. Mingw is based on the *nix GNU Compiler Collection (gcc) which implements the more modern C99 standard allowing variables to be declared anywhere in the body of a function.

If OP's code does not work with MSVC he/she would be much better off using a modern version of mingw or cygwin.

This :)

Also, the c89 implementation resides in msvcrt.dll and has been with us since windows2000 to this day (win8), and is the closest thing you're gonna get to native ansi-c on the doze box.

Embarrased to say that i've never done real unit testing with c/++, but its outthere, should google it around ("C unittest") .. here's one of my first hits (check.h)

http://check.sourceforge.net/doc/check_html/check_3.html

edit again : oh, and I like codeblocks as a lightwegiht alternative to visual studio. (did use bloodshed back in the day thou')
 
Last edited:

cytg111

Lifer
Mar 17, 2008
26,410
15,777
136
Compiled as C++ it will of course work fine. Compiled as C it will fail because MSVC only implements C89.

Edit:
Code:
int main(int argc, char** argv)
{
  for (int i = 0; i < 10; ++i)
  {
  }
  return 0;
}

Compiling the above as C, MSVC10 sez:

Dealing with windows you're never gonna get real c89 right? Coding C on windows in msvc I came to the conclusion that doing a C++ project and only using C89 constructs removed much pain.
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
I have done such in all VS up through '12.

It is a legal feature of the language.

Please post a code snippet of where this failed.

It's been years since I've done C++. I used to have to change this over in college back in 2003-2006. DEV C++ was used by one professor and the labs had VS.
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
First off - don't use Dev C++. Just don't. Pretty please?

Second - the compilers just don't randomly have "different rules". MSVC implements the C89 standard, which requires variables to be declared at the beginning of a scope. Dev-C++ includes an obsolete version of the mingw compiler. Mingw is based on the *nix GNU Compiler Collection (gcc) which implements the more modern C99 standard allowing variables to be declared anywhere in the body of a function.

If OP's code does not work with MSVC he/she would be much better off using a modern version of mingw or cygwin.

Lol that's what I get for remembering my college experience. I probably should have stated I didn't do it since 2006 :)