certi-devel
[Top][All Lists]
Advanced

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

RE: [certi-dev] IEEE1516 RIambassador Checking if (&Object == NULL)


From: Ijperen, Jeroen van
Subject: RE: [certi-dev] IEEE1516 RIambassador Checking if (&Object == NULL)
Date: Fri, 12 Nov 2010 12:10:38 +0100

Hello Eric,

The following piece of code compiles without any warnings in VS 2008 (with /W4).
Yes, it is very evil to do so, however the compiler doesn't even make mention 
of the direct dereference of the NULL pointer.

I do hope that GCC does a better job of catching this error.

--------------------
#include <string>
#include <iostream>

void nullTest(std::string &s) {
        if (&s == NULL)
                std::cout << "Null string" << std::endl;
        else
                std::cout << s << std::endl;
}

int main(int , char **) {
        std::string *s1 = 0;
        std::string *s2 = new std::string("non-null");

        nullTest(*s1);
        nullTest(*s2);

        delete s2;

        return 0;
}
--------------------

I agree that it is the responsibility of the developer to make sure he doesn't 
pass a NULL pointer, but in our application we did not have a need for tags, so 
we always used NULL for them.

Anyway, I agree that checks like should not be required, as it's the developer 
doing something nasty (even if the compiler doesn't warn him about how nasty it 
really is).

Kind regards,

Jeroen v. IJperen


-----Oorspronkelijk bericht-----
Van: address@hidden [mailto:address@hidden Namens Eric Noulard
Verzonden: donderdag 11 november 2010 19:14
Aan: CERTI development discussions
Onderwerp: Re: [certi-dev] IEEE1516 RIambassador Checking if (&Object == NULL)

2010/11/11 Ijperen, Jeroen van <address@hidden>:
> Hello Eric,
>
> You are right that a (const) reference *should* always refer to an object, 
> however this is not enforced by the compiler or runtime. So it actually is 
> possible to dereference a NULL pointer, and pass it as a reference. (To check 
> for this situation, you request the location of the reference, and compare it 
> to NULL.) Basically, it's an extra check to make really sure no one passes a 
> NULL tag (accidentally or on purpose).

In fact I think the extra-check is useless;
http://www.velocityreviews.com/forums/t285972-null-reference.html

I think shall remove it before next release.

May be I'm missing something so you can send me an example on
how to "to dereference a NULL pointer, and pass it as a reference"
without making the compiler cry :-]


--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org

--
CERTI-Devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/certi-devel

TASK24 wordt Nspyre

Vanaf 1 januari 2011 zal TASK24 officieel gaan handelen onder de nieuwe naam 
Nspyre. Per direct wordt de naamswijziging doorgevoerd en zijn de nieuwe Nspyre 
e-mailadressen werkzaam. E-mail gericht aan TASK24 adressen wordt nog bezorgd, 
maar wij verzoeken u vriendelijk uw adresboek aan te passen om voortaan gebruik 
te maken van het Nspyre e-mailadres.



reply via email to

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