Weird C Problem

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
exe\testapp.c(164) : error C2143: syntax error : missing ';' before 'type'

Why can't I declare a variable there (on line 164)? Using nmake compiler in Windows DDK.

BTW with line 164 commented out there are no errors or warnings at all. The code below is inside of a function (VOID _cdecl main( ULONG argc, PCHAR argv[] )).

Apparently it's C89 behavior and MSVC++ 2003 doesn't support C99. :( If you enclose the declaration in braces it works, but any references to that variable must be within the braces as well.
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Well I remember being able to declare them below the top.... I must have been in C++ (.cpp file) mode.

Apparently this is illegal even in C99, according to gcc:

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

You can't declare i within the for loop. Gee, I must have picked up bad habits from somewhere. I find gcc's errors much more descriptive though. I'm really surprised the MS compiler can't do C99.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
ohhh how I hate C's limitations... at least more than half of my work at my job is C++ instead of C
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
I don't suppose drivers could be written in C++? To be honest I prefer C but I'm curious as everything else MS does (in the SDKs) is C++.
 

jman19

Lifer
Nov 3, 2000
11,224
659
126
Originally posted by: dighn
ohhh how I hate C's limitations... at least more than half of my work at my job is C++ instead of C

C has limitations, but C++ is just putrid.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: xtknight
I don't suppose drivers could be written in C++? To be honest I prefer C but I'm curious as everything else MS does (in the SDKs) is C++.
Isn't the windows kernel written in c++?
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Originally posted by: kamper
Originally posted by: xtknight
I don't suppose drivers could be written in C++? To be honest I prefer C but I'm curious as everything else MS does (in the SDKs) is C++.
Isn't the windows kernel written in c++?

No, C as far as I know.

Well:

http://www.microsoft.com/technet/archiv...ntarchitectoview/ntarc_2.mspx?mfr=true

Most of the source code for Windows NT is written in C or C++. These high-level languages make it relatively easy to port Windows NT to different types of workstations. The same source code can be recompiled to build versions of Windows NT that are specific to each processor's instruction set.

A small amount of the code in Windows NT is written in assembly language. Typically, this is code that either interacts directly with a computer's hardware, or needs to run extremely fast. Because assembly language is specific to a particular instruction set, this code must be rewritten once for each type of processor on which Windows NT will run. To make it easy to locate and maintain, this code is isolated to just a few key places in the operating system:
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,674
146
106
www.neftastic.com
Originally posted by: xtknight
Well I remember being able to declare them below the top.... I must have been in C++ (.cpp file) mode.

Apparently this is illegal even in C99, according to gcc:

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

You can't declare i within the for loop. Gee, I must have picked up bad habits from somewhere. I find gcc's errors much more descriptive though. I'm really surprised the MS compiler can't do C99.

Actually - I think you just hit it on the nail there. Rename your source with .cpp and compile it. I'm pretty sure it will work.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Isn't the windows kernel written in c++?

At least their driver model allows drivers to be written in C++, periodically someone always posts to lkml asking how to port a driver written in C++ to Linux.