377 questions
6
votes
4
answers
9k
views
Deleting a null pointer [duplicate]
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 ...
1
vote
1
answer
3k
views
How to handle tinyxml null pointer returned on GetText()
TiXmlElement *pElem;
std::string StatusResponse;
pElem = hResponse.FirstChild("StatusResponse").Element();
if (pElem)
StatusResponse = pElem->GetText();
If pElem is valid but the element ...
4
votes
3
answers
11k
views
NULL passed directly to a function expecting a const reference parameter (VC++ 4.2)
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& ...
0
votes
2
answers
715
views
Access violation on destruction of a null pointer
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 ...
20
votes
3
answers
3k
views
Pointer conversion issue with Ternary operator
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 ...
13
votes
5
answers
7k
views
Assigning a reference by dereferencing a NULL pointer [duplicate]
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 ...
1
vote
2
answers
3k
views
(Open-)JPA 1.0: OneToMany-related list is null, when fetching in lazy mode
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="...
19
votes
3
answers
338
views
How do I prevent trouble arising from std::string being constructed from `0`?
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 ...
0
votes
2
answers
656
views
c++ functional programming ( boost::phoenix && boost::spirit) testing for null-ptrs in pointer placeholders
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 (...
71
votes
9
answers
237k
views
How do we check if a pointer is NULL pointer?
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 ...
29
votes
3
answers
4k
views
Is it undefined behaviour to delete a null void* pointer?
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) ...
2
votes
2
answers
1k
views
C++ Linkedlist simple question
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 ...
3
votes
2
answers
2k
views
C++ Losing pointer reference after scope end
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....
44
votes
8
answers
65k
views
Uninitialized pointers in code
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 ...
106
votes
5
answers
38k
views
Is it guaranteed to be safe to perform memcpy(0,0,0)?
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 ...
6
votes
5
answers
2k
views
Is apparent NULL pointer dereference in C actually pointer arithmetic?
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 ...
50
votes
9
answers
39k
views
What is a void pointer and what is a null pointer?
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 ...
365
votes
8
answers
226k
views
Is it safe to delete a NULL pointer?
Is it safe to delete a NULL pointer?
And is it a good coding style?
3
votes
3
answers
5k
views
Null pattern with QObject
(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 ...
10
votes
3
answers
19k
views
Android - Dealing with a Dialog on Screen Orientation change
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 ...
38
votes
4
answers
22k
views
Calling a method on an uninitialized object (null pointer)
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 (...
13
votes
4
answers
15k
views
Which of these will create a null pointer?
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()...
132
votes
4
answers
19k
views
When does invoking a member function through a null pointer result in undefined behavior?
Consider the following code:
#include <iostream>
struct foo
{
// (a):
void bar() { std::cout << "gman was here" << std::endl; }
// (b):
void baz() { x = 5;...
0
votes
6
answers
1k
views
C89: Access violation reading 0x00 (difficulty with malloc)
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 ...
2
votes
9
answers
13k
views
Can using 0L to initialize a pointer in C++ cause problems?
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 ...
52
votes
8
answers
19k
views
Accessing class members on a NULL pointer
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()
{
...
7
votes
7
answers
2k
views
About the non-nullable types debate
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# ...