Illegal use of this type as an expression

I have mixed function UnloadDriver from two examples:

1-st C:\WinDDK\7600.16385.1\src\general\ioctl\wdm\sys\sioctl.c
2-nd C:\WinDDK\7600.16385.1\src\network\trans\inspect\sys\TL_drv.c

Both sample are compiled separatly, but mixed failed.
Using Windows 7 x86 Checked Build Environment.
Please take a look to code below:

VOID
DriverUnload(
IN PDRIVER_OBJECT driverObject
)
{
//code from 1-st sample

UNICODE_STRING userApplicationName;
PAGED_CODE();
RtlInitUnicodeString(&userApplicationName,DOS_DEVICE_NAME);
IoDeleteSymbolicLink( &userApplicationName );

//code from 2-nd sample

KLOCK_QUEUE_HANDLE connListLockHandle;
KLOCK_QUEUE_HANDLE packetQueueLockHandle;
UNREFERENCED_PARAMETER(driverObject);
KeAcquireInStackQueuedSpinLock(
&gConnListLock,
&connListLockHandle
);
KeAcquireInStackQueuedSpinLock(
&gPacketQueueLock,
&packetQueueLockHandle
);
gDriverUnloading = TRUE;
KeReleaseInStackQueuedSpinLock(&packetQueueLockHandle);
KeReleaseInStackQueuedSpinLock(&connListLockHandle);
if (IsListEmpty(&gConnList) && IsListEmpty(&gPacketQueue))
{
KeSetEvent(
&gWorkerEvent,
IO_NO_INCREMENT,
FALSE
);
}
ASSERT(gThreadObj != NULL);
KeWaitForSingleObject(
gThreadObj,
Executive,
KernelMode,
FALSE,
NULL
);
ObDereferenceObject(gThreadObj);
InspectUnregisterCallouts();
FwpsInjectionHandleDestroy0(gInjectionHandle);
IoDeleteDevice(gDeviceObject);
}

I have an error on “KLOCK_QUEUE_HANDLE connListLockHandle” line with following message “error C2275: ‘KLOCK_QUEUE_HANDLE’ : illegal use of this type as an expression”.

Any help appreciated

Move the KLOCK_QUEUE_HANDLE declarations to the top of the function, right
after the UNICODE_STRING declaration.

xxxxx@gmail.com
Sent by: xxxxx@lists.osr.com
10/25/2010 05:23 PM
Please respond to
“Windows System Software Devs Interest List”

To
“Windows System Software Devs Interest List”
cc

Subject
[ntdev] Illegal use of this type as an expression

I have mixed function UnloadDriver from two examples:

1-st C:\WinDDK\7600.16385.1\src\general\ioctl\wdm\sys\sioctl.c
2-nd C:\WinDDK\7600.16385.1\src\network\trans\inspect\sys\TL_drv.c

Both sample are compiled separatly, but mixed failed.
Using Windows 7 x86 Checked Build Environment.
Please take a look to code below:

VOID
DriverUnload(
IN PDRIVER_OBJECT driverObject
)
{
//code from 1-st sample

UNICODE_STRING userApplicationName;
PAGED_CODE();
RtlInitUnicodeString(&userApplicationName,DOS_DEVICE_NAME);
IoDeleteSymbolicLink( &userApplicationName );

//code from 2-nd sample

KLOCK_QUEUE_HANDLE connListLockHandle;
KLOCK_QUEUE_HANDLE packetQueueLockHandle;
UNREFERENCED_PARAMETER(driverObject);
KeAcquireInStackQueuedSpinLock(
&gConnListLock,
&connListLockHandle
);
KeAcquireInStackQueuedSpinLock(
&gPacketQueueLock,
&packetQueueLockHandle
);
gDriverUnloading = TRUE;
KeReleaseInStackQueuedSpinLock(&packetQueueLockHandle);
KeReleaseInStackQueuedSpinLock(&connListLockHandle);
if (IsListEmpty(&gConnList) && IsListEmpty(&gPacketQueue))
{
KeSetEvent(
&gWorkerEvent,
IO_NO_INCREMENT,
FALSE
);
}
ASSERT(gThreadObj != NULL);
KeWaitForSingleObject(
gThreadObj,
Executive,
KernelMode,
FALSE,
NULL
);
ObDereferenceObject(gThreadObj);
InspectUnregisterCallouts();
FwpsInjectionHandleDestroy0(gInjectionHandle);
IoDeleteDevice(gDeviceObject);
}

I have an error on “KLOCK_QUEUE_HANDLE connListLockHandle” line with
following message “error C2275: ‘KLOCK_QUEUE_HANDLE’ : illegal use of this
type as an expression”.

Any help appreciated


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

C language used to only allow declaration before statements. Unlike C++.

Jerry,

it’s really work, many thanks.

In C all local variables must be declared at the star of a block. In your
code KLOCK_QUEUE_HANDLE is not at the beginning of a block.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, October 25, 2010 5:23 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Illegal use of this type as an expression

I have mixed function UnloadDriver from two examples:

1-st C:\WinDDK\7600.16385.1\src\general\ioctl\wdm\sys\sioctl.c
2-nd C:\WinDDK\7600.16385.1\src\network\trans\inspect\sys\TL_drv.c

Both sample are compiled separatly, but mixed failed.
Using Windows 7 x86 Checked Build Environment.
Please take a look to code below:

VOID
DriverUnload(
IN PDRIVER_OBJECT driverObject
)
{
//code from 1-st sample

UNICODE_STRING userApplicationName;
PAGED_CODE();
RtlInitUnicodeString(&userApplicationName,DOS_DEVICE_NAME);
IoDeleteSymbolicLink( &userApplicationName );

//code from 2-nd sample

KLOCK_QUEUE_HANDLE connListLockHandle;
KLOCK_QUEUE_HANDLE packetQueueLockHandle;
UNREFERENCED_PARAMETER(driverObject);
KeAcquireInStackQueuedSpinLock(
&gConnListLock,
&connListLockHandle
);
KeAcquireInStackQueuedSpinLock(
&gPacketQueueLock,
&packetQueueLockHandle
);
gDriverUnloading = TRUE;
KeReleaseInStackQueuedSpinLock(&packetQueueLockHandle);
KeReleaseInStackQueuedSpinLock(&connListLockHandle);
if (IsListEmpty(&gConnList) && IsListEmpty(&gPacketQueue))
{
KeSetEvent(
&gWorkerEvent,
IO_NO_INCREMENT,
FALSE
);
}
ASSERT(gThreadObj != NULL);
KeWaitForSingleObject(
gThreadObj,
Executive,
KernelMode,
FALSE,
NULL
);
ObDereferenceObject(gThreadObj);
InspectUnregisterCallouts();
FwpsInjectionHandleDestroy0(gInjectionHandle);
IoDeleteDevice(gDeviceObject);
}

I have an error on “KLOCK_QUEUE_HANDLE connListLockHandle” line with
following message “error C2275: ‘KLOCK_QUEUE_HANDLE’ : illegal use of this
type as an expression”.

Any help appreciated


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Guys, you are right, many thanks :slight_smile:

C is syntacticly deficient.

Every time I get stuck with modifying a .c file I regret it.

Mark Roddy

On Mon, Oct 25, 2010 at 5:45 PM, wrote:
> Guys, you are right, many thanks :slight_smile:
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

On Mon, 25 Oct 2010 23:22:55 -0400
Mark Roddy wrote:

> C is syntacticly deficient.
>
> Every time I get stuck with modifying a .c file I regret it.

There are arguments for having all variables declared at the top of the
function - it makes it easier to see how much stack space will be used
for example.

Talk to Microsoft if you think C is deficient - it got fixed over a
decade ago but the Microsoft compiler’s mostly stuck in the 80s.


Bruce Cran

On 10/26/2010 5:22 AM, Mark Roddy wrote:

C is syntacticly deficient.

Every time I get stuck with modifying a .c file I regret it.

C variable declarations can be at the start of any *block*. Just place
variables and code for local processing in a block:

int function(int x) {
int rc;

/* … */

{ /* block for local processing */
int m, o, p;
m = func_a(x);
o = func_b(x, m);
p = func_c(m, o);
rc = func_d(p);
} /* discard m, o, p */

/* … */

return rc;
}

>

On 10/26/2010 5:22 AM, Mark Roddy wrote:
> C is syntacticly deficient.
>
> Every time I get stuck with modifying a .c file I regret it.

C variable declarations can be at the start of any *block*. Just place
variables and code for local processing in a block:

int function(int x) {
int rc;

/* … */

{ /* block for local processing */
int m, o, p;
m = func_a(x);
o = func_b(x, m);
p = func_c(m, o);
rc = func_d(p);
} /* discard m, o, p */

/* … */

return rc;
}

Is the compiler output any different than if m, o, and p were declared
at the same level as rc or is it just a nice way to ensure variable use
in the correct scope?

I like the idea of declaring variables with the narrowest scope possible
but some compilers complain about it (the hazards of ‘portable’ code :slight_smile:

James

I would expect that if all were defined at the same level as ‘rc’ a single
modification of the stack and/or base pointer would modified and nothing
else, but if in a block as written below, you would find another stack/base
pointer modification would occur just before the block is entered. Some
optimizers might combine the second to appear as the first if it makes sense
in an optimized build.

“James Harper” wrote in message
news:xxxxx@ntdev…
>>
>> On 10/26/2010 5:22 AM, Mark Roddy wrote:
>> > C is syntacticly deficient.
>> >
>> > Every time I get stuck with modifying a .c file I regret it.
>>
>> C variable declarations can be at the start of any block. Just place
>> variables and code for local processing in a block:
>>
>> int function(int x) {
>> int rc;
>>
>> /* … /
>>
>> { /
block for local processing /
>> int m, o, p;
>> m = func_a(x);
>> o = func_b(x, m);
>> p = func_c(m, o);
>> rc = func_d(p);
>> } /
discard m, o, p /
>>
>> /
… */
>>
>> return rc;
>> }
>>
>
> Is the compiler output any different than if m, o, and p were declared
> at the same level as rc or is it just a nice way to ensure variable use
> in the correct scope?
>
> I like the idea of declaring variables with the narrowest scope possible
> but some compilers complain about it (the hazards of ‘portable’ code :slight_smile:
>
> James
>

Actually there won’t be a modification to the stack in a smart compiler.
So for the example it will be the same if there are no other local
declarations. What will be different was if another local block
declared x, y, z as int’s then it would be likely that the space on the
stack used for m, o, p would be the same space as used for x, y, z.
This assumes a good optimizing compiler.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“David Craig” wrote in message
news:xxxxx@ntdev:

> I would expect that if all were defined at the same level as ‘rc’ a single
> modification of the stack and/or base pointer would modified and nothing
> else, but if in a block as written below, you would find another stack/base
> pointer modification would occur just before the block is entered. Some
> optimizers might combine the second to appear as the first if it makes sense
> in an optimized build.
>
> “James Harper” wrote in message
> news:xxxxx@ntdev…
> >>
> >> On 10/26/2010 5:22 AM, Mark Roddy wrote:
> >> > C is syntacticly deficient.
> >> >
> >> > Every time I get stuck with modifying a .c file I regret it.
> >>
> >> C variable declarations can be at the start of any block. Just place
> >> variables and code for local processing in a block:
> >>
> >> int function(int x) {
> >> int rc;
> >>
> >> /* … /
> >>
> >> { /
block for local processing /
> >> int m, o, p;
> >> m = func_a(x);
> >> o = func_b(x, m);
> >> p = func_c(m, o);
> >> rc = func_d(p);
> >> } /
discard m, o, p /
> >>
> >> /
… */
> >>
> >> return rc;
> >> }
> >>
> >
> > Is the compiler output any different than if m, o, and p were declared
> > at the same level as rc or is it just a nice way to ensure variable use
> > in the correct scope?
> >
> > I like the idea of declaring variables with the narrowest scope possible
> > but some compilers complain about it (the hazards of ‘portable’ code :slight_smile:
> >
> > James
> >

Yes of course one can work around the syntactic deficiencies of C,
however you haven’t actually done that, you have just narrowed the
scope within which variables are declared while introducing the
potential for more defects.

Mark Roddy

On Wed, Oct 27, 2010 at 4:57 AM, Hagen Patzke wrote:
> On 10/26/2010 5:22 AM, Mark Roddy wrote:
>> C is syntacticly deficient.
>>
>> Every time I get stuck with modifying a .c file I regret it.
>
> C variable declarations can be at the start of any block. Just place
> variables and code for local processing in a block:
>
> int function(int x) {
> ?int rc;
>
> ?/* … /
>
> ?{ /
block for local processing /
> ? ?int m, o, p;
> ? ?m = func_a(x);
> ? ?o = func_b(x, m);
> ? ?p = func_c(m, o);
> ? ?rc = func_d(p);
> ?} /
discard m, o, p /
>
> ?/
… */
>
> ?return rc;
> }
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

>

Yes of course one can work around the syntactic deficiencies of C,
however you haven’t actually done that, you have just narrowed the
scope within which variables are declared while introducing the
potential for more defects.

In what way has the potential for more defects been introduced?

James

Mark Roddy

On Wed, Oct 27, 2010 at 4:57 AM, Hagen Patzke wrote:
> > On 10/26/2010 5:22 AM, Mark Roddy wrote:
> >> C is syntacticly deficient.
> >>
> >> Every time I get stuck with modifying a .c file I regret it.
> >
> > C variable declarations can be at the start of any block. Just place
> > variables and code for local processing in a block:
> >
> > int function(int x) {
> > ?int rc;
> >
> > ?/* … /
> >
> > ?{ /
block for local processing /
> > ? ?int m, o, p;
> > ? ?m = func_a(x);
> > ? ?o = func_b(x, m);
> > ? ?p = func_c(m, o);
> > ? ?rc = func_d(p);
> > ?} /
discard m, o, p /
> >
> > ?/
… */
> >
> > ?return rc;
> > }
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > For our schedule of WDF, WDM, debugging and other seminars visit:
> > http://www.osr.com/seminars
> >
> > To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
> >
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

Inline variable declarations exist in the containing scope’s
namespace. Adding a new scope provides the opportunity to declare
duplicate named objects unintentionally with the usual consequences.

Mark Roddy

On Wed, Oct 27, 2010 at 9:16 AM, James Harper
wrote:
>>
>> Yes of course one can work around the syntactic deficiencies of C,
>> however you haven’t actually done that, you have just narrowed the
>> scope within which variables are declared while introducing the
>> potential for more defects.
>>
>
> In what way has the potential for more defects been introduced?
>
> James
>
>> Mark Roddy
>>
>>
>>
>> On Wed, Oct 27, 2010 at 4:57 AM, Hagen Patzke wrote:
>> > On 10/26/2010 5:22 AM, Mark Roddy wrote:
>> >> C is syntacticly deficient.
>> >>
>> >> Every time I get stuck with modifying a .c file I regret it.
>> >
>> > C variable declarations can be at the start of any block. Just place
>> > variables and code for local processing in a block:
>> >
>> > int function(int x) {
>> > ?int rc;
>> >
>> > ?/* … /
>> >
>> > ?{ /
block for local processing /
>> > ? ?int m, o, p;
>> > ? ?m = func_a(x);
>> > ? ?o = func_b(x, m);
>> > ? ?p = func_c(m, o);
>> > ? ?rc = func_d(p);
>> > ?} /
discard m, o, p /
>> >
>> > ?/
… */
>> >
>> > ?return rc;
>> > }
>> >
>> > —
>> > NTDEV is sponsored by OSR
>> >
>> > For our schedule of WDF, WDM, debugging and other seminars visit:
>> > http://www.osr.com/seminars
>> >
>> > To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>> >
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

This is the same problem that any block structured language has.
Whether you do it at the block level or the statement level (for
instance C++ declarations in statements) the problems are the same.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“Mark Roddy” wrote in message news:xxxxx@ntdev:

> Inline variable declarations exist in the containing scope’s
> namespace. Adding a new scope provides the opportunity to declare
> duplicate named objects unintentionally with the usual consequences.
>
>
> Mark Roddy
>
>
>
> On Wed, Oct 27, 2010 at 9:16 AM, James Harper
> wrote:
> >>
> >> Yes of course one can work around the syntactic deficiencies of C,
> >> however you haven’t actually done that, you have just narrowed the
> >> scope within which variables are declared while introducing the
> >> potential for more defects.
> >>
> >
> > In what way has the potential for more defects been introduced?
> >
> > James
> >
> >> Mark Roddy
> >>
> >>
> >>
> >> On Wed, Oct 27, 2010 at 4:57 AM, Hagen Patzke wrote:
> >> > On 10/26/2010 5:22 AM, Mark Roddy wrote:
> >> >> C is syntacticly deficient.
> >> >>
> >> >> Every time I get stuck with modifying a .c file I regret it.
> >> >
> >> > C variable declarations can be at the start of any block. Just place
> >> > variables and code for local processing in a block:
> >> >
> >> > int function(int x) {
> >> > int rc;
> >> >
> >> > /* … /
> >> >
> >> > { /
block for local processing /
> >> > int m, o, p;
> >> > m = func_a(x);
> >> > o = func_b(x, m);
> >> > p = func_c(m, o);
> >> > rc = func_d(p);
> >> > } /
discard m, o, p /
> >> >
> >> > /
… */
> >> >
> >> > return rc;
> >> > }
> >> >
> >> > —
> >> > NTDEV is sponsored by OSR
> >> >
> >> > For our schedule of WDF, WDM, debugging and other seminars visit:
> >> > http://www.osr.com/seminars
> >> >
> >> > To unsubscribe, visit the List Server section of OSR Online at
> >> http://www.osronline.com/page.cfm?name=ListServer
> >> >
> >>
> >> —
> >> NTDEV is sponsored by OSR
> >>
> >> For our schedule of WDF, WDM, debugging and other seminars visit:
> >> http://www.osr.com/seminars
> >>
> >> To unsubscribe, visit the List Server section of OSR Online at
> >> http://www.osronline.com/page.cfm?name=ListServer
> >
> > —
> > NTDEV is sponsored by OSR
> >
> > For our schedule of WDF, WDM, debugging and other seminars visit:
> > http://www.osr.com/seminars
> >
> > To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
> >

>Is the compiler output any different than if m, o, and p were declared

at the same level as rc or is it just a nice way to ensure variable use
in the correct scope?

Surely the optimizer will rearrange the variables to save the stack space, including using registers, reusing registers and even reusing the stack locations for different variables.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

That IS a problem.

But a well-written compiler will flag that… either as an error (as it does in C#) or with a warning. Prefast will find this problem as well, IIRC.

Peter
OSR

Would not it be called a programming error?

void ff(void)
{
int foo, bar;
foo = bar = 0;

{
int foo = 1;
/* Do fooing */
}

{
int bar = 9;
/* Barring everything in the world */
}

}

Does C# catch this??

-pro

That IS a problem.

But a well-written compiler will flag that… either as an error (as it
does in C#) or with a warning. Prefast will find this problem as well,
IIRC.

Peter
OSR


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Don’t have VS to test with :)?

------ Build started: Project: ConsoleApplication1, Configuration: Debug x86 ------
Program.cs(16,12): error CS0136: A local variable named ‘foo’ cannot be declared in this scope because it would give a different meaning to ‘foo’, which is already used in a ‘parent or current’ scope to denote something else
Program.cs(21,12): error CS0136: A local variable named ‘bar’ cannot be declared in this scope because it would give a different meaning to ‘bar’, which is already used in a ‘parent or current’ scope to denote something else

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@garlic.com
Sent: Wednesday, October 27, 2010 10:32 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Illegal use of this type as an expression

Would not it be called a programming error?

void ff(void)
{
int foo, bar;
foo = bar = 0;

{
int foo = 1;
/* Do fooing */
}

{
int bar = 9;
/* Barring everything in the world */
}

}

Does C# catch this??

-pro

That IS a problem.

But a well-written compiler will flag that… either as an error (as
it does in C#) or with a warning. Prefast will find this problem as
well, IIRC.

Peter
OSR


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer