Is it possible to portablize all #pragma
commands? #pragma once
can be portablize as the following:
#ifndef FOO
#define FOO
//Code here
#endif
However, I am not aware of universal implementations for #pragma pack
and others. Is this possible?
The specification of pragmas in the standard is essentially an implementation-defined hook - the results of every pragma is implementation-defined. The results can include causing translation to fail, the implementation or emitted code behaving in a non-conforming manner (i.e. do things with any code construct differently than the standard requires). Implementations are required to ignore pragmas they don't recognise.
By definition, therefore, there are no universal definitions. There is also nothing preventing two different compilers from doing completely different things with the same pragma.
To "portabilize" such things, it is necessary to have a consistent specification of the features and behaviours that compiler vendors can implement (and, then, that programmers can consistently use). Getting such a specification is challenging but not impossible. Firstly, a specification needs to be shared - formally (e.g. in a standard) or informally (e.g. a specification agreed between some vendors, even if it is not actually in a standard). Second, it requires requires all vendors to agree to implement it - which is not a given, even if it is in a ratified standard. Third, it requires any variations between implementations to be understood, and accepted by developers (or, at the least, a reasonable majority).
When agreement is required between multiple players (vendors, developers, committees, the list goes on) it takes more effort to get agreement. With C++, there is no body that has sufficient "pull" to guarantee that some feature will be successfully "portabilized" - or, to put it another way, there is nobody with a trump vote who can be convinced to make something universal. Getting 100% "portabilization" will be hard - practically, there will often be a "near enough" result rather than 100%.