null-pointer

When are you able to return NULL as the returning value of a C function?

女生的网名这么多〃 提交于 2019-12-02 12:39:01
I was wondering if you could tell me when you are able to return NULL , as the result of a function in C. For instance int lenght() can't return NULL because is is expecting an int in the return statement. But the function struct node* find(int key) , when working with linked lists allows me to return NULL. NULL is a pointer value - or rather a null-pointer value. NULL means that the function can't find where your pointer should point to - for example if you want to open a file, but it doesn't work your file pointer is returned as NULL . So you can test the value of a pointer and check to see

C standard compliant way to access null pointer address?

怎甘沉沦 提交于 2019-11-30 12:41:42
问题 In C, deferencing the null pointer is Undefined Behavior, however the null pointer value has a bit representation that in some architectures make it points to a valid address (e.g the address 0). Let's call this address the null pointer address , for the sake of clarity. Suppose I want to write a piece of software in C, in an environment with unrestrained access to memory. Suppose further I want to write some data at the null pointer address: how would I achieve that in a standard compliant

Is it undefined behaviour to delete a null void* pointer?

怎甘沉沦 提交于 2019-11-30 07:46:31
问题 I know that delete ing 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 ) And also that deleting a void* pointer is undefined behaviour because the destructor can't be called as there are no objects of type void : In the first alternative ( delete object ), the value of the operand of delete shall be a pointer to a non-array object or a pointer to a sub-object

C standard compliant way to access null pointer address?

戏子无情 提交于 2019-11-30 02:48:58
In C, deferencing the null pointer is Undefined Behavior, however the null pointer value has a bit representation that in some architectures make it points to a valid address (e.g the address 0). Let's call this address the null pointer address , for the sake of clarity. Suppose I want to write a piece of software in C, in an environment with unrestrained access to memory. Suppose further I want to write some data at the null pointer address: how would I achieve that in a standard compliant way? Example case (IA32e): #include <stdint.h> int main() { uintptr_t zero = 0; char* p = (char*)zero;

About the non-nullable types debate

橙三吉。 提交于 2019-11-29 14:01:27
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# has introduced non-nullable types to combat this problem. EDIT: Ignore my comment about Spec#. I misunderstood how it works. EDIT 2: I must be talking to the wrong people, I was really hoping for somebody to argue with :-) So I would guess, being in the minority, that I'm wrong, but I can't understand why this debate has any merit. I see null as a bug-finding tool. Consider the following: class

What are the Ruby Win32API Parameters | How do I pass a null pointer?

喜欢而已 提交于 2019-11-29 12:26:31
I know the following: 'L' - Long 'P' - Pointer 'I' - Integer 'V' - Void My problem is that I can't pass a null pointer when I perform an API call. E.g.: ['L', 'P', 'L'] -> api.call(0, nil, 0) :: ArgumentError: Null pointer given . My question is: Are there more parameter types that I don't know about and what should I do to pass a null pointer as a method parameter? Background I have been searching the internet for native Ruby programming examples of WinForms-based applications. I have considered the .NET addition to Ruby known as IronRuby for simplicity in coding (trying to avoid wxRuby, and

Is apparent NULL pointer dereference in C actually pointer arithmetic?

三世轮回 提交于 2019-11-29 07:16:09
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 this a form of pointer arithmetic? struct hi { long a; int b; long c; }; int main() { struct hi ob={3,4,5}; struct hi *ptr=&ob; int num= (unsigned int) & (((struct hi *)0)->b); printf("%d",num); printf("%d",*(int *)((char *)ptr + (unsigned int) & (((struct hi *)0)->b))); } The output I get is 44. But how does it work? This is not an "and", this is taking the address of the right hand side

Is it undefined behaviour to delete a null void* pointer?

别说谁变了你拦得住时间么 提交于 2019-11-29 05:26:49
I know that delete ing 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 ) And also that deleting a void* pointer is undefined behaviour because the destructor can't be called as there are no objects of type void : In the first alternative ( delete object ), the value of the operand of delete shall be a pointer to a non-array object or a pointer to a sub-object representing a base class of such an object. If not, the behavior is undefined. (C++ Standard 5.3.5 [expr.delete

Can't find @Nullable inside javax.annotation.*

淺唱寂寞╮ 提交于 2019-11-28 16:46:29
I want use @Nullable annotation to eliminate NullPointerExceptions . I found some tutorials on the net, I noticed that this annotation comes from the package javax.annotation.Nullable ; but when I import it a compilation error is generated: cannot find symbol david99world You need to include a jar that this class exists in. You can find it here If using Maven, you can add the following dependency declaration: <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <version>3.0.2</version> </dependency> and for Gradle: dependencies { testImplementation 'com

Which of these will create a null pointer?

核能气质少年 提交于 2019-11-28 09:53:05
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() { return reinterpret_cast<X*>(1); } void f() { } }; int main() { X* x = 0; (*x).f(); // the null pointer? (1) x = X::get(); (*x).f(); // the null pointer? (2) x = reinterpret_cast<X*>( X::get() - X::get() ); (*x).f(); // the null pointer? (3) (*(X*)0).f(); // I think that this the only null pointer here (4) } My thought is that dereferencing of the null pointer takes place only in the last case. Am