0

I am making some functions in c which I am going to call from Python via Cython. I am developing these functions in Code:Block using MinGW C++ compiler. But when building them for Python I have to use Visual Microsoft Visual C++ Compiler for Python 2. Then I have met a strang problem. When compiling with Visual C++ compiler I have after a lot of trial and fail found out that all variables have to be decleared before first in each block (if, for, function). Why is so. Are there difference between compilers for c?

4
  • What is your VC++ version? You can also ensure your compiler is not set to compile for C: Project > Properties > Configuration properties > C/C++ > Advanced > Compile As . Check that it is set for C++. Commented Jan 7, 2016 at 15:31
  • I am using Code:Block and MinGW. How do I see which type of c compiler I am using? Commented Jan 7, 2016 at 16:05
  • Do not use a C++ compiler to compile C code! Commented Jan 7, 2016 at 16:08
  • Okay, I have only installed Code:Block and make a C-project. Think I have to read my up on Code:Block in order to find out which compiler it uses. Commented Jan 7, 2016 at 16:36

2 Answers 2

1

MSVC mostly adheres to the original C89 spec. In later revisions of the language this restriction has been lifted.

Sign up to request clarification or add additional context in comments.

Comments

0

In C (proper C rather than C++) the variables have to be declared at the beginning of a block.

1 Comment

@fossekall, MinGW is a C and a C++ compiler. As most compilers, it makes a decision on whether the file it is compiling is supposed to be a C file or a C++ file and then does the compilation. MinGW actually uses a native compiler to do the compilation (unlike gcc which does its own compilation). In case of Windows, that means MinGW is using MS VC++ underneath.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.