cl compiler switch to disable function prototype "guessing"?

Hi there,

using “cl” (still using Windows 2003 DDK, for some reason) to compile my
driver, I’ve stumbled over the following problem:

When compiling a “c” file which calls a function which is not defined in any
of the included headers, the compiler simply seems to guess the calling
convention, parameters and return type, instead of complaining. The linker
might later complain, if the function isn’t found anywhere. But if the function
is properly defined in some other c/h file, then the linker is happy and no
warning is reported anywhere.

Practically, I had the compiler guess an “int” return type, while it really was
a “BOOLEAN” return type. Consequently, the real function was compiled to
“xor al, al”, but the caller was compiled to “test eax, eax”, which resulted in
the return value being seen as “TRUE” while it really was meant to be “FALSE”.

So my question is: Can I force “cl” to error out if a function isn’t
found in any
header file, instead of just guessing the function prototype? I’ve
looked through
all the compiler options, but couldn’t seem to find anything. I’m already using
“/WX”.

I hate compilers trying to be clever… :frowning: If at least it had
posted a warning
like “function definition “x” not found, I’m guessing now”, then it
wouldn’t have
cost me hours to locate the problem.

Thanks, Mathias.

You need to enable warning 4013. Now I have to wonder about your environment since most WDK’s and DDK’s have a #pragma to set that to be an error.

Don Burn
Windows Driver Consulting
Website: http://www.windrvr.com

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of madshi
Sent: Thursday, July 28, 2016 6:37 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] cl compiler switch to disable function prototype “guessing”?

Hi there,

using “cl” (still using Windows 2003 DDK, for some reason) to compile my driver, I’ve stumbled over the following problem:

When compiling a “c” file which calls a function which is not defined in any of the included headers, the compiler simply seems to guess the calling convention, parameters and return type, instead of complaining. The linker might later complain, if the function isn’t found anywhere. But if the function is properly defined in some other c/h file, then the linker is happy and no warning is reported anywhere.

Practically, I had the compiler guess an “int” return type, while it really was a “BOOLEAN” return type. Consequently, the real function was compiled to “xor al, al”, but the caller was compiled to “test eax, eax”, which resulted in the return value being seen as “TRUE” while it really was meant to be “FALSE”.

So my question is: Can I force “cl” to error out if a function isn’t found in any header file, instead of just guessing the function prototype? I’ve looked through all the compiler options, but couldn’t seem to find anything. I’m already using “/WX”.

I hate compilers trying to be clever… :frowning: If at least it had posted a warning like “function definition “x” not found, I’m guessing now”, then it wouldn’t have cost me hours to locate the problem.

Thanks, Mathias.


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

Thanks a lot for the quick and helpful answer, Don.

You need to enable warning 4013.

I’ve added “#pragma warning(error: 4013)” and it does exactly what I
was hoping for.

Now I have to wonder about your environment since most WDK’s and
DDK’s have a #pragma to set that to be an error.

Where do they have that #pragma? In some header file?

I’m using batch compiling. My x64 bat starts like this:

@set OLDDIR=%CD%
@call C:\WINDDK\3790.1830\bin\setenv.bat C:\WINDDK\3790.1830 fre AMD64 WNET
@set Include=c:\winddk\3790.1830\inc\ddk\wnet;c:\winddk\3790.1830\inc\crt;c:\winddk\3790.1830\inc\wnet
@set Lib=C:\WINDDK\3790.1830\lib\crt\amd64;C:\WINDDK\3790.1830\lib\wnet\amd64;C:\WINDDK\3790.1830\lib
@chdir /d %OLDDIR%
@cl

Is there anything else I need to do?

Thanks, Mathias.

2016-07-28 12:51 GMT+02:00 Don Burn :
> You need to enable warning 4013. Now I have to wonder about your environment since most WDK’s and DDK’s have a #pragma to set that to be an error.
>
>
> Don Burn
> Windows Driver Consulting
> Website: http://www.windrvr.com
>
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of madshi
> Sent: Thursday, July 28, 2016 6:37 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] cl compiler switch to disable function prototype “guessing”?
>
> Hi there,
>
> using “cl” (still using Windows 2003 DDK, for some reason) to compile my driver, I’ve stumbled over the following problem:
>
> When compiling a “c” file which calls a function which is not defined in any of the included headers, the compiler simply seems to guess the calling convention, parameters and return type, instead of complaining. The linker might later complain, if the function isn’t found anywhere. But if the function is properly defined in some other c/h file, then the linker is happy and no warning is reported anywhere.
>
> Practically, I had the compiler guess an “int” return type, while it really was a “BOOLEAN” return type. Consequently, the real function was compiled to “xor al, al”, but the caller was compiled to “test eax, eax”, which resulted in the return value being seen as “TRUE” while it really was meant to be “FALSE”.
>
> So my question is: Can I force “cl” to error out if a function isn’t found in any header file, instead of just guessing the function prototype? I’ve looked through all the compiler options, but couldn’t seem to find anything. I’m already using “/WX”.
>
> I hate compilers trying to be clever… :frowning: If at least it had posted a warning like “function definition “x” not found, I’m guessing now”, then it wouldn’t have cost me hours to locate the problem.
>
> Thanks, Mathias.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></http:></http:></http:>

Check warning.h for the pragma.

Don Burn
Windows Driver Consulting
Website: http://www.windrvr.com

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of madshi
Sent: Thursday, July 28, 2016 9:34 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] cl compiler switch to disable function prototype “guessing”?

Thanks a lot for the quick and helpful answer, Don.

> You need to enable warning 4013.

I’ve added “#pragma warning(error: 4013)” and it does exactly what I was hoping for.

> Now I have to wonder about your environment since most WDK’s and DDK’s
> have a #pragma to set that to be an error.

Where do they have that #pragma? In some header file?

I’m using batch compiling. My x64 bat starts like this:

@set OLDDIR=%CD%
@call C:\WINDDK\3790.1830\bin\setenv.bat C:\WINDDK\3790.1830 fre AMD64 WNET @set Include=c:\winddk\3790.1830\inc\ddk\wnet;c:\winddk\3790.1830\inc\crt;c:\winddk\3790.1830\inc\wnet
@set Lib=C:\WINDDK\3790.1830\lib\crt\amd64;C:\WINDDK\3790.1830\lib\wnet\amd64;C:\WINDDK\3790.1830\lib
@chdir /d %OLDDIR%
@cl

Is there anything else I need to do?

Thanks, Mathias.

2016-07-28 12:51 GMT+02:00 Don Burn :
> You need to enable warning 4013. Now I have to wonder about your environment since most WDK’s and DDK’s have a #pragma to set that to be an error.
>
>
> Don Burn
> Windows Driver Consulting
> Website: http://www.windrvr.com
>
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of madshi
> Sent: Thursday, July 28, 2016 6:37 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] cl compiler switch to disable function prototype “guessing”?
>
> Hi there,
>
> using “cl” (still using Windows 2003 DDK, for some reason) to compile my driver, I’ve stumbled over the following problem:
>
> When compiling a “c” file which calls a function which is not defined in any of the included headers, the compiler simply seems to guess the calling convention, parameters and return type, instead of complaining. The linker might later complain, if the function isn’t found anywhere. But if the function is properly defined in some other c/h file, then the linker is happy and no warning is reported anywhere.
>
> Practically, I had the compiler guess an “int” return type, while it really was a “BOOLEAN” return type. Consequently, the real function was compiled to “xor al, al”, but the caller was compiled to “test eax, eax”, which resulted in the return value being seen as “TRUE” while it really was meant to be “FALSE”.
>
> So my question is: Can I force “cl” to error out if a function isn’t found in any header file, instead of just guessing the function prototype? I’ve looked through all the compiler options, but couldn’t seem to find anything. I’m already using “/WX”.
>
> I hate compilers trying to be clever… :frowning: If at least it had posted a warning like “function definition “x” not found, I’m guessing now”, then it wouldn’t have cost me hours to locate the problem.
>
> Thanks, Mathias.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at:
> http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at
> http:
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at:
> http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at
> http:


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></http:></http:></http:></http:></http:></http:>

It’s set correctly in “warning.h”, but the only reference to
“warning.h” I could find is in “makefile.new”.

Through which way is “warning.h” supposed to be included in my driver?

Thanks, Mathias.

2016-07-28 15:47 GMT+02:00 Don Burn :
> Check warning.h for the pragma.
>
>
> Don Burn
> Windows Driver Consulting
> Website: http://www.windrvr.com
>
>
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of madshi
> Sent: Thursday, July 28, 2016 9:34 AM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] cl compiler switch to disable function prototype “guessing”?
>
> Thanks a lot for the quick and helpful answer, Don.
>
>> You need to enable warning 4013.
>
> I’ve added “#pragma warning(error: 4013)” and it does exactly what I was hoping for.
>
>> Now I have to wonder about your environment since most WDK’s and DDK’s
>> have a #pragma to set that to be an error.
>
> Where do they have that #pragma? In some header file?
>
> I’m using batch compiling. My x64 bat starts like this:
>
> @set OLDDIR=%CD%
> @call C:\WINDDK\3790.1830\bin\setenv.bat C:\WINDDK\3790.1830 fre AMD64 WNET @set Include=c:\winddk\3790.1830\inc\ddk\wnet;c:\winddk\3790.1830\inc\crt;c:\winddk\3790.1830\inc\wnet
> @set Lib=C:\WINDDK\3790.1830\lib\crt\amd64;C:\WINDDK\3790.1830\lib\wnet\amd64;C:\WINDDK\3790.1830\lib
> @chdir /d %OLDDIR%
> @cl
>
> Is there anything else I need to do?
>
> Thanks, Mathias.
>
>
> 2016-07-28 12:51 GMT+02:00 Don Burn :
>> You need to enable warning 4013. Now I have to wonder about your environment since most WDK’s and DDK’s have a #pragma to set that to be an error.
>>
>>
>> Don Burn
>> Windows Driver Consulting
>> Website: http://www.windrvr.com
>>
>>
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of madshi
>> Sent: Thursday, July 28, 2016 6:37 AM
>> To: Windows System Software Devs Interest List
>> Subject: [ntdev] cl compiler switch to disable function prototype “guessing”?
>>
>> Hi there,
>>
>> using “cl” (still using Windows 2003 DDK, for some reason) to compile my driver, I’ve stumbled over the following problem:
>>
>> When compiling a “c” file which calls a function which is not defined in any of the included headers, the compiler simply seems to guess the calling convention, parameters and return type, instead of complaining. The linker might later complain, if the function isn’t found anywhere. But if the function is properly defined in some other c/h file, then the linker is happy and no warning is reported anywhere.
>>
>> Practically, I had the compiler guess an “int” return type, while it really was a “BOOLEAN” return type. Consequently, the real function was compiled to “xor al, al”, but the caller was compiled to “test eax, eax”, which resulted in the return value being seen as “TRUE” while it really was meant to be “FALSE”.
>>
>> So my question is: Can I force “cl” to error out if a function isn’t found in any header file, instead of just guessing the function prototype? I’ve looked through all the compiler options, but couldn’t seem to find anything. I’m already using “/WX”.
>>
>> I hate compilers trying to be clever… :frowning: If at least it had posted a warning like “function definition “x” not found, I’m guessing now”, then it wouldn’t have cost me hours to locate the problem.
>>
>> Thanks, Mathias.
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list online at:
>> http:
>>
>> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
>> Details at http:
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http:
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list online at:
>> http:
>>
>> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
>> Details at http:
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http:
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></http:></http:></http:></http:></http:></http:></http:></http:></http:>

This behavior has been there since C was created, it is described in K&R

Get Outlook for Androidhttps:

On Thu, Jul 28, 2016 at 7:18 AM -0700, “madshi” > wrote:

It’s set correctly in “warning.h”, but the only reference to
“warning.h” I could find is in “makefile.new”.

Through which way is “warning.h” supposed to be included in my driver?

Thanks, Mathias.

2016-07-28 15:47 GMT+02:00 Don Burn :
> Check warning.h for the pragma.
>
>
> Don Burn
> Windows Driver Consulting
> Website: http://www.windrvr.com
>
>
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of madshi
> Sent: Thursday, July 28, 2016 9:34 AM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] cl compiler switch to disable function prototype “guessing”?
>
> Thanks a lot for the quick and helpful answer, Don.
>
>> You need to enable warning 4013.
>
> I’ve added “#pragma warning(error: 4013)” and it does exactly what I was hoping for.
>
>> Now I have to wonder about your environment since most WDK’s and DDK’s
>> have a #pragma to set that to be an error.
>
> Where do they have that #pragma? In some header file?
>
> I’m using batch compiling. My x64 bat starts like this:
>
> @set OLDDIR=%CD%
> @call C:\WINDDK\3790.1830\bin\setenv.bat C:\WINDDK\3790.1830 fre AMD64 WNET @set Include=c:\winddk\3790.1830\inc\ddk\wnet;c:\winddk\3790.1830\inc\crt;c:\winddk\3790.1830\inc\wnet
> @set Lib=C:\WINDDK\3790.1830\lib\crt\amd64;C:\WINDDK\3790.1830\lib\wnet\amd64;C:\WINDDK\3790.1830\lib
> @chdir /d %OLDDIR%
> @cl
>
> Is there anything else I need to do?
>
> Thanks, Mathias.
>
>
> 2016-07-28 12:51 GMT+02:00 Don Burn :
>> You need to enable warning 4013. Now I have to wonder about your environment since most WDK’s and DDK’s have a #pragma to set that to be an error.
>>
>>
>> Don Burn
>> Windows Driver Consulting
>> Website: http://www.windrvr.com
>>
>>
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of madshi
>> Sent: Thursday, July 28, 2016 6:37 AM
>> To: Windows System Software Devs Interest List
>> Subject: [ntdev] cl compiler switch to disable function prototype “guessing”?
>>
>> Hi there,
>>
>> using “cl” (still using Windows 2003 DDK, for some reason) to compile my driver, I’ve stumbled over the following problem:
>>
>> When compiling a “c” file which calls a function which is not defined in any of the included headers, the compiler simply seems to guess the calling convention, parameters and return type, instead of complaining. The linker might later complain, if the function isn’t found anywhere. But if the function is properly defined in some other c/h file, then the linker is happy and no warning is reported anywhere.
>>
>> Practically, I had the compiler guess an “int” return type, while it really was a “BOOLEAN” return type. Consequently, the real function was compiled to “xor al, al”, but the caller was compiled to “test eax, eax”, which resulted in the return value being seen as “TRUE” while it really was meant to be “FALSE”.
>>
>> So my question is: Can I force “cl” to error out if a function isn’t found in any header file, instead of just guessing the function prototype? I’ve looked through all the compiler options, but couldn’t seem to find anything. I’m already using “/WX”.
>>
>> I hate compilers trying to be clever… :frowning: If at least it had posted a warning like “function definition “x” not found, I’m guessing now”, then it wouldn’t have cost me hours to locate the problem.
>>
>> Thanks, Mathias.
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list online at:
>> http:
>>
>> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
>> Details at http:
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http:
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> Visit the list online at:
>> http:
>>
>> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
>> Details at http:
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http:
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></http:></http:></http:></http:></http:></http:></http:></http:></http:></http:></http:></http:></https:>

madshi wrote:

using “cl” (still using Windows 2003 DDK, for some reason) to compile my
driver, I’ve stumbled over the following problem:

When compiling a “c” file which calls a function which is not defined in any
of the included headers, the compiler simply seems to guess the calling
convention, parameters and return type, instead of complaining. The linker
might later complain, if the function isn’t found anywhere. But if the function
is properly defined in some other c/h file, then the linker is happy and no
warning is reported anywhere.

Doron is right. This is what standard C requires. If you want stricter
type checking on function prototypes, use C++.

I hate compilers trying to be clever… :frowning: If at least it had
posted a warning like “function definition “x” not found, I’m guessing now”,
then it wouldn’t have cost me hours to locate the problem.

That’s the legacy. It is doing what a C compiler is supposed to do.
This is why C has nearly disappeared, outside of the embedded community.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Tim Roberts wrote:

Doron is right.

Strange, I’m not seeing Doron’s reply in my email folder (yet?), but I
can see it on www.osronline.com. Anyway…

Tim Roberts wrote:

This is what standard C requires. If you want stricter
type checking on function prototypes, use C++.

Using C++ for driver development? Euwh!!

It is doing what a C compiler is supposed to do.

Ok. Thankfully, Don’s suggestion to enable warning 4013 has solved my
biggest concerns.

Thanks, Mathias.

2016-07-28 18:18 GMT+02:00 Tim Roberts :
> madshi wrote:
>> using “cl” (still using Windows 2003 DDK, for some reason) to compile my
>> driver, I’ve stumbled over the following problem:
>>
>> When compiling a “c” file which calls a function which is not defined in any
>> of the included headers, the compiler simply seems to guess the calling
>> convention, parameters and return type, instead of complaining. The linker
>> might later complain, if the function isn’t found anywhere. But if the function
>> is properly defined in some other c/h file, then the linker is happy and no
>> warning is reported anywhere.
>
> Doron is right. This is what standard C requires. If you want stricter
> type checking on function prototypes, use C++.
>
>
>> I hate compilers trying to be clever… :frowning: If at least it had
>> posted a warning like “function definition “x” not found, I’m guessing now”,
>> then it wouldn’t have cost me hours to locate the problem.
>
> That’s the legacy. It is doing what a C compiler is supposed to do.
> This is why C has nearly disappeared, outside of the embedded community.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

madshi wrote:

Tim Roberts wrote:
> This is what standard C requires. If you want stricter
> type checking on function prototypes, use C++.
Using C++ for driver development? Euwh!!

You’ll find me as an active participant in the C vs C++ wars we’ve had
on the mailing list over the years. Even if you don’t find classes and
polymorphism to be of benefit in your driver work (I certainly do), it’s
also possible to use “C++ as a better C” without using classes, just to
gain the stricter type checking that C++ offers. Merely renaming your
.c file to .cpp can act as a miniature “lint”.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Or turning on /W4 which will give you most of the C++ checking without the C++ problems.

Don Burn
Windows Driver Consulting
Website: http://www.windrvr.com

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, July 28, 2016 2:47 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] cl compiler switch to disable function prototype “guessing”?

madshi wrote:
> Tim Roberts wrote:
>> This is what standard C requires. If you want stricter type checking
>> on function prototypes, use C++.
> Using C++ for driver development? Euwh!!

You’ll find me as an active participant in the C vs C++ wars we’ve had on the mailing list over the years. Even if you don’t find classes and polymorphism to be of benefit in your driver work (I certainly do), it’s also possible to use “C++ as a better C” without using classes, just to gain the stricter type checking that C++ offers. Merely renaming your .c file to .cpp can act as a miniature “lint”.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

This.

Highly recommended.

Peter
OSR
@OSRDrivers

On 7/28/16 10:49 AM, madshi wrote:

> Doron is right. This is what standard C requires. If you want stricter
> type checking on function prototypes, use C++.

Or upgrade to a newer C compiler which supports something more recent
than C89. The default int ‘feature’ was removed in C99, and since then
C11 (ISO/IEC 9899:2011) has been released - see
https://en.wikipedia.org/wiki/C11_(C_standard_revision) for more details.


Bruce

> So my question is: Can I force “cl” to error out if a function isn’t

found in any
header file, instead of just guessing the function prototype? I’ve
looked through
all the compiler options, but couldn’t seem to find anything. I’m already using
“/WX”.

/W4 /WX


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

Tim Roberts wrote:

Merely renaming your .c file to .cpp can act as a miniature “lint”.

Thanks, I might give that a try.

Don Burn wrote:

Or turning on /W4 which will give you most of the C++ checking
without the C++ problems.
Maxim S. Shatskih wrote:
/W4 /WX

Interesting. I thought that /WX would include /W4. I’ll add both, just
to be safe.

Thanks all!

Now I’m facing a somewhat related issue, but with the linker instead
of the compiler. In many of my “c” files I’m using a global
“CritSection” variable. I thought that C defaults to “static” scope
for global variables? At least that’s what this site claims:

http://os.camden.rutgers.edu/c_resources/c_manual/C/CONCEPT/storage_class.html

But now I’ve found out (by accident) that the linker somehow merges
all the “CritSection” global vars of all the “c” files into one,
without any warnings or complaints. So I basically only have one
critical section (mutex) in all my driver instead of one per “c” file,
which is obviously very bad. So 2 questions:

  1. It seems “static” is *not* the default scope for global vars? Or
    did I maybe use some compiler option by accident which changed the
    scope?

  2. I’m using “link.exe”, without using the “/force” option, but with
    the “/WX” option. Shouldn’t the linker complain if it finds multiple
    non-static variables with the same name? I mean that’s the complaint
    that “/force:multiple” is meant to disable, right? So if I don’t use
    “/force” at all, it should complain, shouldn’t it?

Thanks again!

Best regards, Mathias.

2016-07-29 21:53 GMT+02:00 Maxim S. Shatskih :
>> So my question is: Can I force “cl” to error out if a function isn’t
>> found in any
>> header file, instead of just guessing the function prototype? I’ve
>> looked through
>> all the compiler options, but couldn’t seem to find anything. I’m already using
>> “/WX”.
>
> /W4 /WX
>
> –
> Maxim S. Shatskih
> Microsoft MVP on File System And Storage
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

This is kind of a new phenomenon, isn’t it?

What makes people think they should learn a programming language by writing a driver? Or is it that they need to write a driver, but don’t know C, so… You know… Java isn’t that hard, it’s almost C, maybe I’ll just “wing it”??

Peter
OSR
@OSRDrivers

Wow. That was really insulting, Peter. Try being helpful instead of
talking down to a fellow dev.

FYI, I don’t know Java. I do know C++ and Assembler (and Pascal/Delphi).

Best regards, Mathias.

2016-08-04 14:31 GMT+02:00 :
> This is kind of a new phenomenon, isn’t it?
>
> What makes people think they should learn a programming language by writing a driver? Or is it that they need to write a driver, but don’t know C, so… You know… Java isn’t that hard, it’s almost C, maybe I’ll just “wing it”??
>
> Peter
> OSR
> @OSRDrivers
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

madshi wrote:

Now I’m facing a somewhat related issue, but with the linker instead
of the compiler. In many of my “c” files I’m using a global
“CritSection” variable. I thought that C defaults to “static” scope
for global variables? At least that’s what this site claims:

That site is wrong. Global variables are “extern” by default in both
languages. C and C++ do differ slightly in the way externs are defined,
however.

In C, a global variable without an initializer is externed, but it is
“tentatively” defined. What this means is if you have:
x.c:
int xxx;
y.c:
int xxx;
z.c:
int xxx;

All three of those refer to the same space, and it will be initialized
to zero by the linker. If you have this:
x.c:
int xxx;
y.c:
int xxx = 7;
z.c:
int xxx;

The definition in “y.c” is promoted from a “tentative” declaration to an
initialized extern. All three of those refer to the same space, and it
will be initialized to 7. This produces a linker error for
multiply-defined symbol:
x.c:
int xxx;
y.c:
int xxx = 7;
z.c:
int xxx = 9;

In C++, there is no tentative definition. All global declarations
without “extern” have a default initialization, so the following
produces a “multiply defined” error:
x.cpp:
int xxx;
y.cpp:
int xxx;
z.cpp:
int xxx;

The correct method is to have one file claim ownership, and the others
link to it:
x.cpp:
int xxx;
y.cpp:
extern int xxx;
z.cpp:
extern int xxx;


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

@Tim,

thanks a lot for the detailed explanation. Everything is 100% clear to
me now. I suppose just renaming the files to cpp (as you suggested
earlier) might have done the trick here, too. So I’ll definitely try
that now. Who knows where else it might help.

Best regards, Mathias.

2016-08-04 18:31 GMT+02:00 Tim Roberts :
> madshi wrote:
>>
>> Now I’m facing a somewhat related issue, but with the linker instead
>> of the compiler. In many of my “c” files I’m using a global
>> “CritSection” variable. I thought that C defaults to “static” scope
>> for global variables? At least that’s what this site claims:
>
> That site is wrong. Global variables are “extern” by default in both
> languages. C and C++ do differ slightly in the way externs are defined,
> however.
>
> In C, a global variable without an initializer is externed, but it is
> “tentatively” defined. What this means is if you have:
> x.c:
> int xxx;
> y.c:
> int xxx;
> z.c:
> int xxx;
>
> All three of those refer to the same space, and it will be initialized
> to zero by the linker. If you have this:
> x.c:
> int xxx;
> y.c:
> int xxx = 7;
> z.c:
> int xxx;
>
> The definition in “y.c” is promoted from a “tentative” declaration to an
> initialized extern. All three of those refer to the same space, and it
> will be initialized to 7. This produces a linker error for
> multiply-defined symbol:
> x.c:
> int xxx;
> y.c:
> int xxx = 7;
> z.c:
> int xxx = 9;
>
> In C++, there is no tentative definition. All global declarations
> without “extern” have a default initialization, so the following
> produces a “multiply defined” error:
> x.cpp:
> int xxx;
> y.cpp:
> int xxx;
> z.cpp:
> int xxx;
>
> The correct method is to have one file claim ownership, and the others
> link to it:
> x.cpp:
> int xxx;
> y.cpp:
> extern int xxx;
> z.cpp:
> extern int xxx;
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>

madshi wrote:

Wow. That was really insulting, Peter. Try being helpful instead of
talking down to a fellow dev.

Please don’t attempt criticism until you have been here long enough to
understand the ecosystem. Most of the “fixtures” here have been in the
driver world for decades. We’re offering our hard-earned expertise for
gratis. Questions that seem to lean towards the “newbie” side raise
particular ire.

Peter, in particular, is an owner in the company that provides the
equipment that hosts this list as a courtesy to the community. It’s his
yard, and these are his toys. He makes the rules.

FYI, I don’t know Java. I do know C++ and Assembler (and Pascal/Delphi).

But apparently not the differences between C and C++. If you’re
comfortable in C++, write your driver in C++. It’s just that easy.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> Please don’t attempt criticism until you have been here long

enough to understand the ecosystem.

Fair enough. I do very much appreciate the great help I’ve been
getting. I’ve read many other threads in this list over the years, and
I think it’s one of the very best (if not the best) lists out there
for devs.

English is not my native language, so maybe I read something into
Peter’s comment that he didn’t mean to say. To me his comment sounded
as if he considered me to be a Java script kiddie trying to do stuff
out of my league. And that seemed insulting to me, especially because
he doesn’t know much about me. If I misinterpreted his comment, I
apologize.

It’s true that I don’t have much experience with C. I always thought
of C++ as being something like “C with classes”. So I thought knowing
C++ meant I could do C without any problems, too. And it worked out
fine for me so far, except for getting less warnings than I’m used to
from C++ compilers/linkers. But I can take a hint, so I’ll try to move
my driver sources to C++ now.

Thanks again, Mathias.

2016-08-04 19:04 GMT+02:00 Tim Roberts :
> madshi wrote:
>> Wow. That was really insulting, Peter. Try being helpful instead of
>> talking down to a fellow dev.
>
> Please don’t attempt criticism until you have been here long enough to
> understand the ecosystem. Most of the “fixtures” here have been in the
> driver world for decades. We’re offering our hard-earned expertise for
> gratis. Questions that seem to lean towards the “newbie” side raise
> particular ire.
>
> Peter, in particular, is an owner in the company that provides the
> equipment that hosts this list as a courtesy to the community. It’s his
> yard, and these are his toys. He makes the rules.
>
>
>> FYI, I don’t know Java. I do know C++ and Assembler (and Pascal/Delphi).
>
> But apparently not the differences between C and C++. If you’re
> comfortable in C++, write your driver in C++. It’s just that easy.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at: http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:>