Re: What's the idea behind the png_constcast() macro implementation?

Cosmin Truta <[email protected]> Sun, 4 Feb 2018 00:02:56 -0500
Newsgroups gmane.comp.graphics.png.devel
Message-ID <CAAoVtZx+KM1=VBMYvPj_X37TBmFKyKpf=dbbzLKiUkCTcTbbkg@mail.gmail.com>
On 2 February 2018 at 03:20, Stephan Mühlstrasser wrote:
> On IBM iSeries it is not possible to cast pointer types to integer types and
> back to pointer types. See for example here:
>
> https://www.ibm.com/support/knowledgecenter/SSAE4W_9.6.0/com.ibm.etools.iseries.pgmgd.doc/cpprog448.htm

Thank you, Stephan. In the light of your report, I propose to
deprecate png_ptruint in future libpng 1.6.x releases, and remove it
completely in libpng-1.7, for portability reasons. This type did not
need to exist in the older libpng versions (which worked just fine
without it), and the present-day libpng should still be able to work
just fine without it.

> The question is, what is the idea behind the intermediate cast to
> png_ptruint in the png_constcast() macro, before the (type) cast is applied?

That's a good question. Whatever the idea might have been, it probably
sounded well at the time when this type was introduced. I suspect that
it sounded well because of the lack of awareness of the following
pretty important detail:

The standard C99/C++11 types intptr_t and uintptr_t are optional, not
mandatory. For example, in the POSIX world, only the XSI-conformant
systems are required to provide this type.

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html

This is not a superficial matter of the C library implementation
opting to implement it (or not), but a more fundamental matter of the
platform being able to store a pointer into an integer and then put
that back into a pointer (or not). It doesn't work everywhere. Most
notably, it doesn't work on IBM iSeries, because AFAIK the hardware
doesn't allow it, by design.

> I did a quick test with gcc on Linux and Visual Studio on Windows, and
> leaving out the (png_ptruint) did not cause a warning.

Thank you, that's good to know.

Sincerely,
Cosmin

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
png-mng-implement mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/png-mng-implement