Viladoman / StructLayout

Visual Studio Extension for C++ struct memory layout visualization
MIT License
477 stars 22 forks source link

Support Precompiled Headers & #pragma once #41

Open Nopey opened 1 year ago

Nopey commented 1 year ago

In my project, there are many precompiled headers such as this:

// common.h
#pragma once

class Common {
    int field1;
    char field2;
    void *field3;
};

If common.h is precompiled, StructLayout's clang will fail to compile the header; clang ignores the #pragma once directive on the primary source file.

To side-step this issue, the plugin could take an alternative approach:
Generate a new sourcefile, structlayout.cpp:

#include "common.h" // this will respect #pragma once, if present
class StructLayoutTarget {
    Common real_target;
};

The plugin would then invoke clang with the appropriate headers, pch's, defines, etc as it does now, but targeting structlayout.cpp and its StructLayoutTarget class instead of targeting common.h and its Common class.

Related: #40