help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Invalid cast


From: Frederic Mayot
Subject: Invalid cast
Date: 6 Feb 2007 08:50:49 -0800
User-agent: G2/1.0

Hi,
Can someone give me an explanation why the following code produces a
bug. I think it's related to the compiler and that the first line is
not OK. I have no pb with gcc 3.4 but the bug appeared with gcc 4.1.1
A* p = ...;
int l;
(char*&)p += l;
The right way is
p = reinterpret_cast<A*>(reinterpret_cast<char*>(p) + l);
Thanks
Fred



reply via email to

[Prev in Thread] Current Thread [Next in Thread]