I'm sorry if I didn't convey my meaning properly, I was interrupted
before I completed.

Here's a better example, while pretty contrived, that shows how the
compiler can optimize away things due to aliasing rules.

What do you expect the output of the printf to be?  In the -O2 and
better case, I can tell you that gcc 4.4 differs from gcc 4.5, and is
probably not what you expect.

#include <stdio.h>

int main()
{
  unsigned int itmp; unsigned short stmp;
  unsigned int i = 0x12345678;
  double f = 3.14159265358979323846;

  unsigned short* sarr = (unsigned short*)&i;
  unsigned int* iarr = (unsigned int*)&f;

  itmp = *iarr; *iarr = *(iarr+1); *(iarr+1) = itmp;
  stmp = *sarr; *sarr = *(sarr+1); *(sarr+1) = stmp;
  printf("swapped float = %0.25g,  swapped int = 0x%X\n", f, i);
  return 0;
}

On that note, what you ran across is a difference in how glibc is
behaving with respect to malloc versus how gcc expects malloc to
behave.  We suffered the same issue recently with the math functions
that were potentially writing to a global unexpectedly....basically
our declarations "lied" to gcc about the behavior of the functions
:)...

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to