How does Visual Studio decide on the field names in a C structure when doing a quick watch on the structure?

Theodore Sung 0 Reputation points
2025-02-18T22:47:49.76+00:00

Programming in C. I was curious how/where Visual Studio is determining the field names of a structure when one does a quick watch on the pointer to the structure's memory. The reason is a bit odd but here it is:

we have a client facing structure that is also used internally our API. Internally we want the field to be one name but to the client we want it to be another name. So we've been playing with redefining the field name in various header files but are curious how Visual Studio decides which field name to actually display in Quick Watch or the Watch Window.

Thanks, Ted

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,858 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Theodore Sung 0 Reputation points
    2025-02-19T01:39:29.0166667+00:00

    Let me clarify a bit. main.c looks like this:

    #include "testicmo.h"

    int main( int nargs, char * argv[] {

    foo();
    
    X *xp = calloc( 1, sizeof( X ) );
    

    where testicmo.h looks like this:

    #ifndef X_DEFINED

    typedef struct _X {

    int armi_index ;               /* ARM index# - offset in the icmo_vindex_info[] array */
    
    }  X ;
    

    #define X_DEFINED

    #endif

    so according to the definition, I should see armi_index in the debugger.

    But I have another C file (call it foo.c and I'll link to the object) that looks like this:

    #include "testcmo.h"

    void foo() {

    X *xp = (X *)calloc( 1, sizeof( X ) );
    
    }
    

    and testcmo.h has

    /* Should be defined before include icmo.h : */

    #define armi_index armi_index_external

    #include "testicmo.h"

    /* Should be redefined after include icmo.h : */

    #undef armi_index

    #define armi_index armi_index_internal

    #endif /* CMO_H_INCLUDED */

    So when I compile foo.c, the field name is getting redefined but when I compile the main.c, it does not.

    How does the debugger know what field name to use for the structure X?

    Thanks, Ted


  2. Bruce (SqlWork.com) 71,591 Reputation points
    2025-02-20T16:48:21.6+00:00

    typedef's are scoped to the source using them. the debugger uses the symbol table generated for each source, to know what properties a typedef has in that source.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.