Page 1 of 1

[resolved]: Reserved identifier "I" in "magick/statistic.h"

Posted: 2014-10-03T23:50:30-07:00
by davidaciko
I set the following message as an email, but your server directed me here. The reserved identifier in question is a single uppercase "I" (sounds like "eye").

- - -

I have used your binary for years and today I decided to use your API in a commercial project in particular need of some magick. I am using MagickCore because I am a wizard.

In the file: "magick/statistic.h", lines 50-51, the following is stated:

double I[32];

However, this statement uses the identifier "I" which is reserved by the standard library header "complex.h" as a macro defined in n1570 ยง7.3.1 (n1570 is the final draft of the C11 standard ISO/IEC 9899:201x).

According to the standard cited above (page 188):

"The macro
" I
"expands to either _Imaginary_I or _Complex_I. If _Imaginary_I is not
"defined, I shall expand to _Complex_I.
"
"Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then
"redefine the macros complex, imaginary, and I."

Therefore, a line should be inserted somewhere before line 51 in "magick/statistic.h" as the following #undef to satisfy the standard:

#undef I

By adding the above line between lines 50 and 51, I was able to compile the API. It would be nice if you redefine it afterwards since this takes place in a public header file that people will #include in their own source:

#if defined(_Imaginary_I)
# define I _Imaginary_I
#else
# define I _Complex_I
#endif

I haven't gotten very far in the MagickCore API manual yet (I only first downloaded the source about an hour ago), so I'm not yet sure to what extent "double I[32]" or its containing struct, "struct _ChannelMoments" (aka "ChannelMoments") is used, but I recommend you consider deprecating the old identifier "I" in a major version release some time in the future to avoid conflicts with the standard library. To avoid problems like this in the future, you can #include all the standard library headers (C89, C94, C99, and C11) above your own headers in a test program to make sure there are no conflicts.


I hope this helps!

David >^,^<

Re: [BUG]: Reserved identifier "I" in "magick/statistic.h"

Posted: 2014-10-04T14:49:03-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick 6.8.9-9 Beta, available by sometime tomorrow. Thanks.

Re: [BUG]: Reserved identifier "I" in "magick/statistic.h"

Posted: 2014-10-08T08:04:57-07:00
by davidaciko
You are awesome, thank you!