This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Assign pointers of different objects to the same pointer
- From: "Duft Markus" <Markus dot Duft at salomon dot at>
- To: "sebastian" <sebastian dot bw at freenet dot de>, <gcc-help at gcc dot gnu dot org>
- Date: Fri, 6 Jul 2007 15:33:54 +0200
- Subject: RE: Assign pointers of different objects to the same pointer
Hi!
Use void*:
MyType1* var1;
void* ptr;
ptr = var1;
// C-Style cast
var1 = (MyType1*)ptr;
// Dynamic cast, checks types at runtime
var1 = dynamic_cast<MyType1*>(ptr);
// Reinterpret cast does the same as C-Style cast (at least i think so)
var1 = reinterpret_cast<MyType1*>(ptr);
....
Also you may want to look at the other *_cast operators (static_cast,
etc)...
Sorry, i don't want to insult you, but this made me laugh ;o)
Cheers, Markus
sebastian <> wrote:
> Is there a possibility to break through the ISO-C++ standard with a
> instruction in gcc that let me assign different objects (&Types) to
> the same pointer?
>
> Best will be to let allow the declaration of a typeless pointer (
> NULL *p; or NULL p;) that can be assigned with every other pointer of
> an object (class initialisation or void members (void
> FunctionName(void) ).
> So only pointers get handled and called and memory(stack) keeps being
> conform. So only the functionality of the programme can change on
> programmer's mistakes.
>
> Best example is QPointer of QT. QPointer would then be not necessary
> any more if ISO-C++ or GCC allow (implement) this.
--
Salomon Automation GmbH - Friesachstrasse 15 - A-8114 Friesach bei Graz
Sitz der Gesellschaft: Friesach bei Graz
UID-NR:ATU28654300 - Firmenbuchnummer: 49324 K
Firmenbuchgericht: Landesgericht fur Zivilrechtssachen Graz