• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Testing basic C code in a separate IDE?

gregulator

Senior member
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!
 
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.
 
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.
 
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.
 
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.
 
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:
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.
 
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:
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.
 
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.
 
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 🙂
 
Back
Top