Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7942 Discussions

How correctly use #pragma loop count?

max-divulskiy
Beginner
7,177 Views
Good afternoon.
Prompt please as correctly it is necessary to write
[bash]#pragma loop count (N)[/bash]
Src or Src.

or it is necessary to write as it is specified in Intel C++ Compiler User & Reference Guides:
[bash]#pragma loop_count (N)[/bash]

Why so it is a lot of different interpretations?

Really developers from Intel do not use file WinDef.h or Windows.h where define ?
[bash]#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif[/bash]
because of what there is a conflict in #pragma:
[bash]#pragma loop_count min(n), max(n), avg(n)[/bash]
Excuse me for my English.
0 Kudos
4 Replies
Quoc-An_L_Intel
Moderator
7,177 Views

"#pragma loop_count" is an Intel compiler specific pragma, and I would suggest that you use what is documented in the product documentation.

As for the "conflict" with Windows.h, I assume that you are referring to the following warning:

>>>t.c(13): warning #54: too few arguments in macro invocation #pragma loop count min(3), max(10), avg(5)

>>>t.c(13) : warning C4068: unknown pragma t.c(13) : warning C4003: not enough actual parameters for macro 'min'

>>>t.c(13) : warning C4003: not enough actual parameters for macro 'max'

This warning warns the users that min, max, avg when use in this context (with #pragma loop_count) has a different meaning than what is provided in Windows.h You can disable this warning with the option /Qwd54, where the number 54 refers to the identifier of the warning.

Note that Microsoft gives you a similar warnings:

>>>t.c(13) : warning C4068: unknown pragma t.c(13) : warning C4003: not enough actual parameters for macro 'min'

>>>t.c(13) : warning C4003: not enough actual parameters for macro 'max'

0 Kudos
Marián__VooDooMan__M
New Contributor II
7,177 Views
Quoting Qale (Intel)

"#pragma loop_count" is an Intel compiler specific pragma, and I would suggest that you use what is documented in the product documentation.

As for the "conflict" with Windows.h, I assume that you are referring to the following warning:

>>>t.c(13): warning #54: too few arguments in macro invocation #pragma loop count min(3), max(10), avg(5)

>>>t.c(13) : warning C4068: unknown pragma t.c(13) : warning C4003: not enough actual parameters for macro 'min'

>>>t.c(13) : warning C4003: not enough actual parameters for macro 'max'

This warning warns the users that min, max, avg when use in this context (with #pragma loop_count) has a different meaning than what is provided in Windows.h You can disable this warning with the option /Qwd54, where the number 54 refers to the identifier of the warning.

Note that Microsoft gives you a similar warnings:

>>>t.c(13) : warning C4068: unknown pragma t.c(13) : warning C4003: not enough actual parameters for macro 'min'

>>>t.c(13) : warning C4003: not enough actual parameters for macro 'max'

Greetings,

though I am trying ICC 13.0 (beta ATM), but I feel this case doesn't matter.

I have eliminated warning by "/Qwd54" as you suggested.

My question is: When "min", "max" and "avg" are macros from Microsoft's headers, will ICC honour this pragma anyaway?
0 Kudos
Georg_Z_Intel
Employee
7,177 Views
Hello,

it's true that both min(...) and max(...) are defined macros inherited by inclusion of "windows.h" ("WinDef.h" to be precise).
This means that the pre-processor will substitute all occurrences of both min(...) and max(...) before invoking the compiler. Hence, if you write something like that:

[cpp]#include 

...
#pragma loop_count min(10), max(100), avg(25)[/cpp]

...the preprocessor will generate this:

[cpp]#pragma loop_count (((10) < ()) ? (10) : ()), (((100) > ()) ? (100) : ()), avg(25)[/cpp]

This is definitely not what you want. On Linux*/Mac OS* X you won't have this problem, by the way.

The correct solution is to use the alternative syntax:

[cpp]#pragma loop_count min=10, max=100, avg=25[/cpp]

Best regards,

Georg Zitzlsberger
0 Kudos
SergeyKostrov
Valued Contributor II
7,177 Views
Quoting muved
...
Really developers from Intel do not use file WinDef.h or Windows.h where define ?
  1. #ifndefmax
  2. #definemax(a,b)(((a)>(b))?(a):(b))
  3. #endif
  4. #ifndefmin
  5. #definemin(a,b)(((a)<(b))?(a):(b))
  6. #endif
[bash]#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

#ifndef min
#define min(a,b)            (((a) < (b)) ? (a) : (b))
#endif[/bash]
...

Problems with 'min' and 'max' macros are very old anda couple of years ago I decided to stop using these
macros. On a project I'm currently working two new macros are used instead, like:

#define CrtMin ...
and
#define CrtMax ...

They finally isolated codes from oldissues with classically defined macros.

Best regards,
Sergey
0 Kudos
Reply