@floooh @lritter @greenmoonmoon Yes, but that does not require #pragma pack at all. Just the explicit padding members are enough.

@manx @lritter @greenmoonmoon

> At that point, #pragma pack is kind of pointless, because it does nothing.

...the whole point of the thread is to make the content of padding bytes explicitly defined, and this is one way to do it (the other solution that came up is to use a compiler-specific builtin to zero the padding bytes, not yet supported by clang though)

@floooh @lritter @greenmoonmoon At that point, #pragma pack is kind of pointless, because it does nothing. You have already filled all the holes that packing would eliminate.
If you want to model alignment that does not match the language alignment rules precisely (i.e. GPU, or file formats), I would strongly suggest doing what boost::endian does: Use distinct types that are naturally byte aligned (i.e. arrays of bytes), and (in C) accessor functions or (in C++) implicit conversions.
@floooh @lritter @greenmoonmoon Packed structs are almost never "safe" in any way.
As soon as you pass a reference or pointer to a packed and non-aligned member in that struct, you are in Undefined Behaviour land, because non-aligned objects must not exist, and the compiler will break that basically immediately. The non-alignedness is not encoded in the type system, neither for #pragma pack, nor for __attribute__((packed)).
A simple call to std::min is enough to break things.

@floooh @lritter @greenmoonmoon Yeah, surrounding the structs you want this on with:

#pragma pack(push, 1)

// structs

#pragma pack(pop)

That's right, right? Been a while since I learnt about that.

@jk

#pragma. not even once.

@Lapizistik #PRAGMA DO_WHAT_I_MEAN

Funktioniert bei mir schon seit Jahren 😂

@funkylab I agree with you about the semantics around if directives in this particular example. The unclear part is the definition of what “#pragma once” actually does. You could argue that in the second processing of the file, when it sees the pragma, it knows that the file is already being processed lower in the file stack. So you could reason: maybe it should abort the processing and assume the file had been processed.

@funkylab it’s really to do with it not being standardised more than anything else. Like what is the expectation of preprocessing the following file lol.h

#ifndef foo
#define foo
#else
#pragma once
#endif
#include "lol.h"
Yo

Is it a single “Yo” or two lines of “Yo”?

If it was defined that it needed to be the first thing in a file following whitespace, I think i’f be fine with it.

I’m writing a C preprocessor (don’t even ask) and it’s horrible. I literally have the c90 and c99 specs in front of me and still keep using clang to preprocess code snippets to see what it does with edge cases. The whole thing has vibes of “write a formal spec that describes this exact awful C program using 50x as much english text as code in the program”. Also “#pragma once” is awful.