Pragmas are "directives" for the compiler, which affect the compilation process.
Pragma "Once" is usually (always ?) used at the beginning of a file . h that will be included in other source files . c or . cpp (or even other .h). This pragma instructs the compiler to read this file only once, even if the compilation flow of a source implies reading it more than once.
For example:
- there is a include file "a. h", with pragma "Once" in the first line
- there is a include "b. h" file that includes "a. h"
- there is a include "c.h" file that includes "a. h"
- there is a "p.c" file that includes "b. h" and "c.h"
The compiler, reading "p.c", includes (reads) "b. h", and reading "b. h" also includes "a. h". Then the compiler (still processing "p.c") includes "c.h" and discovers that it should include "a. h", but as "a. h" has already been included in "b. h", no new inclusion of "a. h".
The pragma "pack" controls the alignment of members of a structure. Normally, for reasons of efficiency a structure like this:
struct
{
char c;
int i;
} s;
has a 3-byte "hole" between "c" and "i", to "align" the address of "i" at a multiple address of 4, as it is usually more efficient for the processor to access an "int" that has a multiple address of 4.
Using a pragma pack(1), for example, we can avoid the occurrence of these "holes" at the cost of a probable inefficiency in access to the "i" member of the structure.
#pragma pack(1) // força alinhamento de 1
struct
{
char c;
int i;
} s;
#pragma pack() // volta o alinhamento default
The pragma "comment" if I’m not mistaken embeds strings in executable code, but I’m not sure.
how can I be making a signature?
– Brumazzi DB
I never did, I believe it would be something like this
#pragma comment(user, "texto aqui")
.– Maniero