Skip to main content
Filter by
Sorted by
Tagged with
6 votes
4 answers
9k views

Possible Duplicate: Is there any reason to check for a NULL pointer before deleting? I often see the following in code: if(pointer) delete pointer; To my understanding it is safe to delete a ...
user987280's user avatar
  • 1,628
1 vote
1 answer
3k views

TiXmlElement *pElem; std::string StatusResponse; pElem = hResponse.FirstChild("StatusResponse").Element(); if (pElem) StatusResponse = pElem->GetText(); If pElem is valid but the element ...
Smurf64's user avatar
  • 337
4 votes
3 answers
11k views

I am looking at something that I discovered in an old code base, and I am pretty confused. Here is a function definition: void vUpdateSequenceDetailsAndIncrement( const CallEvent& ...
Dennis's user avatar
  • 3,741
0 votes
2 answers
715 views

The problem I am having is that when my class CLimb runs its destructor, if member *parent is NULL I get an "Access violation writing location 0xcccccccc" error, after the destructor is called, but ...
Elliot Hatch's user avatar
  • 1,220
20 votes
3 answers
3k views

I know the ternary operator has some surprising restrictions, but I was a bit baffled that this fails to compile for me: void foo(bool b) { int* ptr = ((b) ? NULL : NULL); } Obviously that's the ...
Roddy's user avatar
  • 68.5k
13 votes
5 answers
7k views

int& fun() { int * temp = NULL; return *temp; } In the above method, I am trying to do the dereferencing of a NULL pointer. When I call this function it does not give exception. I found ...
G Mann's user avatar
  • 461
1 vote
2 answers
3k views

I have a problem with JPA 1.0 (OpenJPA) Following situation @Entity public class A{ private Long aId; private List<B> bEntities; //myId getter and setter @OneToMany(mappedBy="...
asotbb's user avatar
  • 119
19 votes
3 answers
338 views

void foo (const std::string &s) {} int main() { foo(0); //compiles, but invariably causes runtime error return 0; } The compiler (g++ 4.4) apparently interprets 0 as char* NULL, and ...
leftaroundabout's user avatar
0 votes
2 answers
656 views

So, I have the following spirit karma rule body: base_rule = eps(_r1 != 0) [ // _r1 is a pointer_typed placeholder eps ] ; which leads to a rather long error message from g++ which (...
Hassan Syed's user avatar
  • 20.6k
71 votes
9 answers
237k views

I always think simply if(p != NULL){..} will do the job. But after reading this Stack Overflow question, it seems not. So what's the canonical way to check for NULL pointers after absorbing all ...
cpuer's user avatar
  • 7,923
29 votes
3 answers
4k views

I know that deleteing a null pointer is a no-op: In either alternative, if the value of the operand of delete is the null pointer the operation has no effect. (C++ Standard 5.3.5 [expr.delete] p2) ...
Xeo's user avatar
  • 132k
2 votes
2 answers
1k views

I'm trying to check if an entity exists in a given linkedlist. This is my code: bool LinkedList::existByID(int ID) { //create node to search through the list Node * helpNode; //start it at the top ...
BIU's user avatar
  • 2,469
3 votes
2 answers
2k views

I'm getting a really weird error where after I leave the for scope I can't access whatever my pointer was pointing during the loop even if the array holding the objects is declared in the class header....
Luke B.'s user avatar
  • 1,308
44 votes
8 answers
65k views

I am learning C++ and I came to know that pointers if left uninitialized could point to random locations in memory and create problems that memory might be used by some other program. Now if that is ...
munish's user avatar
  • 4,694
106 votes
5 answers
38k views

I am not so well-versed in the C standard, so please bear with me. I would like to know if it is guaranteed, by the standard, that memcpy(0,0,0) is safe. The only restriction I could find is that if ...
Matthieu M.'s user avatar
6 votes
5 answers
2k views

I've got this piece of code. It appears to dereference a null pointer here, but then bitwise-ANDs the result with unsigned int. I really don't understand the whole part. What is it intended to do? Is ...
karthik A's user avatar
  • 665
50 votes
9 answers
39k views

So I was going through some interview questions and I came across one about void and null pointers, which claims: a pointer with no return type is called a null pointer. It may be any kind of ...
Shouvik's user avatar
  • 11.8k
365 votes
8 answers
226k views

Is it safe to delete a NULL pointer? And is it a good coding style?
qiuxiafei's user avatar
  • 6,047
3 votes
3 answers
5k views

(C++/Qt) I have a smart pointer to a QObject. Let's say a QWeakPointer. For some external reason (something that might happen in another object or due to an event), it is possible that the pointed ...
user427569's user avatar
10 votes
3 answers
19k views

I am overriding the onCreateDialog and onPrepareDialog methods or the Dialog class. I have followed the example from Reto Meier's Professional Android Application Development book, Chapter 5 to pull ...
Donal Rafferty's user avatar
38 votes
4 answers
22k views

What is the normal behavior in Objective-C if you call a method on an object (pointer) that is nil (maybe because someone forgot to initialize it)? Shouldn't it generate some kind of an error (...
Florin's user avatar
  • 1,844
13 votes
4 answers
15k views

The standard says that dereferencing the null pointer leads to undefined behaviour. But what is "the null pointer"? In the following code, what we call "the null pointer": struct X { static X* get()...
big-z's user avatar
  • 7,172
132 votes
4 answers
19k views

Consider the following code: #include <iostream> struct foo { // (a): void bar() { std::cout << "gman was here" << std::endl; } // (b): void baz() { x = 5;...
GManNickG's user avatar
  • 506k
0 votes
6 answers
1k views

I am developing C89 on Visual Studio 2010 Ultimate Beta (Win 7). I don't think I'm using malloc() correctly. I am new to C, so please excuse the beginner question. The goal of my program is to count ...
Nick Heiner's user avatar
2 votes
9 answers
13k views

In this question an initializer is used to set a pointer to null. Instead of using value of 0 value of 0L is used. I've read that one should use exactly 0 for null pointers because exact null pointer ...
sharptooth's user avatar
  • 171k
52 votes
8 answers
19k views

I was experimenting with C++ and found the below code as very strange. class Foo{ public: virtual void say_virtual_hi(){ std::cout << "Virtual Hi"; } void say_hi() { ...
Navaneeth K N's user avatar
7 votes
7 answers
2k views

I keep hearing people talk about how non-nullable reference types would solve so many bugs and make programming so much easier. Even the creator of null calls it his billion dollar mistake, and Spec# ...
zildjohn01's user avatar
  • 11.6k

1
4 5 6 7
8