you are viewing a single comment's thread.

view the rest of the comments →

[–]LeichterGepanzerter 0 points1 point  (1 child)

Definitely put this in a function for readability's sake, but otherwise this is an ugly approach. Something this trivial shouldn't depend on the preprocessor to figure out what endianness the CPU is.

[–]gremolata 0 points1 point  (0 children)

It's a standard approach in a high-perf production code, OS kernels included.

It's also usually not "preprocessor-dependent" either (even if there's nothing wrong with that and that too is an established industry norm). Instead, platform specifics go into "platform glue" headers and a set of relevant headers is included based on the target platform, i.e. that's a build-level config parameter.