StructLayout icon indicating copy to clipboard operation
StructLayout copied to clipboard

Support Precompiled Headers & #pragma once

Open Nopey opened this issue 1 year ago • 0 comments

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

Nopey avatar Aug 26 '23 18:08 Nopey