Meaning of "pragmatic" [closed]

What is the meaning of pragmatic in this example?

Another C construct, the #pragma directive, is used to instruct the compiler to use pragmatic or implementation-dependent features. A most notable user of this directive is OpenMP.

According to online dictionary, pragmatic means:

Dealing with things sensibly and realistically in a way that is based on practical rather than theoretical considerations.

But I can't see how this explains the word in the example above.


Someone with better knowledge of this directive might have a more specific answer, but I think the context answers the question you are asking:

...is used to instruct the compiler to use pragmatic or implementation-dependent features.

That is, "pragmatic" in this context means "implementation-dependent." A pragma directive gives the compiler directions on how to interact with a specific architecture, for instance. Pragmas are a means to accomplish something efficiently (in a practical or pragmatic way) that might have a better theoretical solution.

In contrast, "implementation-independent" features are the ideal (non-pragmatic) way to design code. By using "implementation-independent" features, the code is theoretically self-contained and universally interoperable. This theoretical ideal is difficult in practice because of the heterogeneity of platforms and the diversity of interface methods. Using a directive that allows you to adapt code directly to a specific implementation is a lot more practical than trying to design something that is generic enough to work with every implementation.

Wiktionary has an entry on pragmas that might shed some light.


It's a matter of doing what you need to do (in practical terms) rather than what the C standard strictly allows you to do.

Suppose you want to put a very short delay into your code. You might write something like this:

{
    int i;

    for (i = 0; i < 100000; i++)
        ;
}

It looks nice and simple; just repeatedly increment a variable and then throw it away. The trouble is that a sensible optimiser will spot that this code does exactly nothing and throw the whole thing away, leaving you with no delay. You could switch the optimiser off when you run the compiler, but you don't want to do that because it makes the rest of your program larger and less efficient.

If you stick rigidly to the standard, you are a bit stuck at this point. You could put this snippet in a file of its own and compile it separately with the optimiser off. That would be a more theoretically satisfying answer, but it comes with maintenance nightmares, the overhead of an extra function call, and so on.

The pragmatic answer, if your compiler supports such a thing, is to stick

#pragma optimisation_off
/* code here */
#pragma optimisation_on

around the code you want left alone.

(The real answer is to declare i as volatile or better yet not to write delays with spin loops, but let's ignore that for the sake of example.)