Discussion:
Variables with internal linkage - how to view?
(too old to reply)
Frank S
2008-03-26 22:20:47 UTC
Permalink
I have a variable declared like:

static const CString test = "abc";

Which debug window do I use to view this variable, which has "internal linkage"?

Thanks,

Frank
Charles Wang[MSFT]
2008-03-27 03:42:16 UTC
Permalink
Hi Frank,
I am not sure of your meaning of "internal linkage", but you can view the
variable in Immediate Window or adding a Watch Window. If either of the two
windows is not displayed when you are debugging, you can manually select
the menu Debug->Window->Immediate or Debug->Window->Watch->Watch 1.

Hope this helps. If you have any other questions or concerns, please feel
free to let me know.

Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: ***@microsoft.com.
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
Frank S
2008-03-27 13:57:19 UTC
Permalink
Post by Charles Wang[MSFT]
Hi Frank,
I am not sure of your meaning of "internal linkage", but you can view the
variable in Immediate Window or adding a Watch Window. If either of the two
windows is not displayed when you are debugging, you can manually select
the menu Debug->Window->Immediate or Debug->Window->Watch->Watch 1.
Hope this helps. If you have any other questions or concerns, please feel
free to let me know.
Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
I tried using a watch window, but that only solves part of the problem. I want to see several
"internal linkage" variables at the same time, where each has the same name. When I watch several
with the same name, there seems to be no way to distinguish between them, and the value shown is the
same for all.

The only method that has worked so far is to hover over the variable while I am at a breakpoint in
the file containing the internal linkage variable. But I want to see several at once.

Thanks,

Frank
Charles Wang[MSFT]
2008-03-28 12:15:09 UTC
Permalink
Hi Frank,
Is it possible for you to post some code snippets here for explaining your
question?

I understand that internal linkage variables are those variables declared
as static or const without extern etc. However I am not sure if I
understand your meaning of "I want to see several internal linkage
variables at the same time, where each has the same name." Are you in a
multi-threading environment? If so, I am afraid that you could not see them
all at the same time since they have different execution contexts. Setting
breakpoints can help you view the variable one by one in debugging
environment. However if you want to get a list for viewing all of them, you
may consider adding some trace function before or after using them in debug
mode.

Please feel free to let me know if you have any other questions or
concerns. Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: ***@microsoft.com.
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
David Lowndes
2008-03-28 14:20:19 UTC
Permalink
Post by Charles Wang[MSFT]
I understand that internal linkage variables are those variables declared
as static or const without extern etc. However I am not sure if I
understand your meaning of "I want to see several internal linkage
variables at the same time, where each has the same name."
Charles,

Is Frank perhaps referring to nested blocks with the same variable
name:

{
int x = 0;
...
{
int x = 2;
.. when execution is here, how do I see the x in the outer block?


Dave
Tom Serface
2008-03-28 23:09:47 UTC
Permalink
I always think that is a scary programming technique, but if I did have code
like that I'd likely just try hovering the cursor over either to see if the
compiler keeps them straight. Don't know what would happen in a watch
window though.

Tom
Post by David Lowndes
Post by Charles Wang[MSFT]
I understand that internal linkage variables are those variables declared
as static or const without extern etc. However I am not sure if I
understand your meaning of "I want to see several internal linkage
variables at the same time, where each has the same name."
Charles,
Is Frank perhaps referring to nested blocks with the same variable
{
int x = 0;
...
{
int x = 2;
.. when execution is here, how do I see the x in the outer block?
Dave
David Lowndes
2008-03-29 09:09:39 UTC
Permalink
Post by Tom Serface
I always think that is a scary programming technique
Indeed it is - in fact the static analyser warns against it.
Post by Tom Serface
but if I did have code
like that I'd likely just try hovering the cursor over either to see if the
compiler keeps them straight.
I think that's what Frank was saying did work for him - and I guess if
that works there must be some internal way for the debugger to get
that information. I've no idea if there's any syntax magic that could
be used to get it in the watch window though.

Dave
Frank S
2008-03-29 13:04:52 UTC
Permalink
Post by David Lowndes
Post by Tom Serface
I always think that is a scary programming technique
Indeed it is - in fact the static analyser warns against it.
Post by Tom Serface
but if I did have code
like that I'd likely just try hovering the cursor over either to see if the
compiler keeps them straight.
I think that's what Frank was saying did work for him - and I guess if
that works there must be some internal way for the debugger to get
that information. I've no idea if there's any syntax magic that could
be used to get it in the watch window though.
Dave
My code is not that scary.

I have a variable in each of several .cpp files that has the same name and has internal linkage.
It is declared like:

static const CString test = "abc";

I can see a particular variable fine by hovering over the name. I want a method to see several at once.

Regards,

Frank
Tom Serface
2008-03-29 15:28:32 UTC
Permalink
Hi Frank,

I'm guessing even if you added the variables to the watch window you would
only see the one that is in context for the block you are in (in David's
example at least). Are you saying you have multiple static consts with the
same name or just that you are creating a local with the same name as the
static. In the first place I doubt it would link, but in the second case
you're likely only going to see the value for the most recent scope except
with the hovering technique which evaluates the scope based on placement.

Maybe for the sake of testing you could rename your statics and add
something like _S on the end?

Tom
Post by Frank S
Post by David Lowndes
Post by Tom Serface
I always think that is a scary programming technique
Indeed it is - in fact the static analyser warns against it.
Post by Tom Serface
but if I did have code like that I'd likely just try hovering the cursor
over either to see if the compiler keeps them straight.
I think that's what Frank was saying did work for him - and I guess if
that works there must be some internal way for the debugger to get
that information. I've no idea if there's any syntax magic that could
be used to get it in the watch window though.
Dave
My code is not that scary.
I have a variable in each of several .cpp files that has the same name and
has internal linkage.
static const CString test = "abc";
I can see a particular variable fine by hovering over the name. I want a
method to see several at once.
Regards,
Frank
Charles Wang[MSFT]
2008-03-31 10:05:16 UTC
Permalink
Hi Frank,
I am not sure what exactly your code looks like. I assume that you have the
code snippets like the following:
//---a.cpp
int CA::GetVariableLen(){
static const CString TEST = _T("aaaa");
return TEST.GetAllocLength();
}

//--b.cpp
int CB::GetVariableLen(){
static const CString TEST = _T("bbb");
CA aa;
int nLenA = aa.GetVariableLen();
int nLenB = TEST.GetAllocLength();
return nLenA>nLenB ? nLenA : nLenB;
}

At upper level, you execute the following code:
CB bb;
int n = bb.GetVariableLen();
......

and you would like to know the TEST constant values in both
CA::GetVariableLen and CB::GetVariableLen() after you call
bb.GetVariableLen() outside or aa.GetVariableLen() within
CB::GetVariableLen().

In this case, I recommend that you use TRACE macro to record their runtime
values so that you can see the list of them in the Output window. For
example:
int CA::GetVariableLen(){
static const CString TEST = _T("aaaa");
TRACE(_T("TEST in CA::GetVariableLen():") + TEST + _T("\n"));
return TEST.GetAllocLength();
}


int CB::GetVariableLen(){
static const CString TEST = _T("bbb");
TRACE(_T("TEST in CB::GetVariableLen():") + TEST + _T("\n"));
CA aa;
int nLenA = aa.GetVariableLen();
int nLenB = TEST.GetAllocLength();
return nLenA>nLenB ? nLenA : nLenB;
}

Then in the Output window, you can find the following output when you debug
your application in Visual Studio:
TEST in CB::GetVariableLen():bbb
TEST in CA::GetVariableLen():aaaa

Hope this helps. If you have any other questions or concerns, please feel
free to let me know.

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: ***@microsoft.com.
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
Charles Wang[MSFT]
2008-04-02 15:02:02 UTC
Permalink
Hi Frank,
Would you mind letting us know the issue status? Please feel free to let us
know if you have any further questions or concerns. Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: ***@microsoft.com.
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
Frank S
2008-04-04 13:34:37 UTC
Permalink
Post by Charles Wang[MSFT]
Hi Frank,
Would you mind letting us know the issue status? Please feel free to let us
know if you have any further questions or concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
It seems the debugger can't do what I wanted, viewing multiple internal-linkage variables with the
same name at the same time. I'll accept this as a known limitation.

Regards,

Frank
Charles Wang[MSFT]
2008-04-07 02:48:05 UTC
Permalink
Hi Frank,
Thank you for your response.

If you have any concerns regarding this limitation, we really welcome your
feedback at https://connect.microsoft.com/visualstudio where your voice
will be heard by Microsoft product team and you can also get email
notification from the product team when they respond to you.

Please feel free to let us know if you have any other questions or
concerns. Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: ***@microsoft.com.
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================

Frank S
2008-03-27 14:03:28 UTC
Permalink
Post by Charles Wang[MSFT]
Hi Frank,
I am not sure of your meaning of "internal linkage", but you can view the
variable in Immediate Window or adding a Watch Window. If either of the two
windows is not displayed when you are debugging, you can manually select
the menu Debug->Window->Immediate or Debug->Window->Watch->Watch 1.
Hope this helps. If you have any other questions or concerns, please feel
free to let me know.
Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
From the MSDN documentation:

Static (C++)
Example See Also Send Feedback


When modifying a variable, the static keyword specifies that the variable has static duration (it is
allocated when the program begins and deallocated when the program ends) and initializes it to 0
unless another value is specified. When modifying a variable or function at file scope, the static
keyword specifies that the variable or function has internal linkage (its name is not visible from
outside the file in which it is declared).

----

The variables I am talking about are declared at file scope.

Regards,

Frank
Loading...