__declspec(selectany) confusion

Hi,
I have seen that if I put the following in a header file :
extern __declspec(selectany) __declspec(allocate(“mysection”)) UCHAR buf1[4]
= {0};
extern __declspec(selectany) __declspec(allocate(“mysection”)) UCHAR buf2[4]
= {0};

then in the runtime buf1 actually equals buf2. It seems that when
__declspec(selectany) and __declspec(allocate(“mysection”)) are used
together, the compiler optimizes them to a single buffer. Is there a way to
prevent this when __declspec(selectany) and
__declspec(allocate(“mysection”)) are used together?
Thanks!

Jicun Zhong

From what I remember about the docs for __declspec(selectany) (which I
use in WDF), you should not use extern with it. You should declare buf1
and buf2 in the header w/out the extern and let the compiler pick the
instance. If you think about it extern and selectany are mutually
exclusive. selectany says pick any of these global definitions which
are all the same and extern says there is a global definition somewhere
else.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jicun Zhong
Sent: Friday, July 16, 2004 3:27 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] __declspec(selectany) confusion

Hi,
I have seen that if I put the following in a header file :
extern __declspec(selectany) __declspec(allocate(“mysection”)) UCHAR
buf1[4]
= {0};
extern __declspec(selectany) __declspec(allocate(“mysection”)) UCHAR
buf2[4]
= {0};

then in the runtime buf1 actually equals buf2. It seems that when
__declspec(selectany) and __declspec(allocate(“mysection”)) are used
together, the compiler optimizes them to a single buffer. Is there a way
to
prevent this when __declspec(selectany) and
__declspec(allocate(“mysection”)) are used together?
Thanks!

Jicun Zhong

Hi Doron,
I tried with extern removed, but the problem still exists. Thanks for the
tip anyway.

Jicun

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Friday, July 16, 2004 4:36 PM
Subject: RE: [ntdev] __declspec(selectany) confusion

>From what I remember about the docs for__declspec(selectany) (which I
use in WDF), you should not use extern with it. You should declare buf1
and buf2 in the header w/out the extern and let the compiler pick the
instance. If you think about it extern and selectany are mutually
exclusive. selectany says pick any of these global definitions which
are all the same and extern says there is a global definition somewhere
else.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jicun Zhong
Sent: Friday, July 16, 2004 3:27 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] __declspec(selectany) confusion

Hi,
I have seen that if I put the following in a header file :
extern__declspec(selectany) __declspec(allocate(“mysection”)) UCHAR
buf1[4]
= {0};
extern__declspec(selectany) __declspec(allocate(“mysection”)) UCHAR
buf2[4]
= {0};

then in the runtime buf1 actually equals buf2. It seems that when
__declspec(selectany) and __declspec(allocate(“mysection”)) are used
together, the compiler optimizes them to a single buffer. Is there a way
to
prevent this when__declspec(selectany) and
__declspec(allocate(“mysection”)) are used together?
Thanks!

Jicun Zhong


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@vallcom.com
To unsubscribe send a blank email to xxxxx@lists.osr.com