null-pointer

Do the following statements assign either physical or virtual address to a pointer?

与世无争的帅哥 提交于 2019-12-11 06:36:54
问题 From https://stackoverflow.com/a/2761494/156458 neither C nor C++ provides a strictly defined feature that would allow you to assign a specific physical address to a pointer. So your question about "how one would assign 0 address to a pointer" formally has no answer. You simply can't assign a specific address to a pointer in C/C++. However, in the realm of implementation-defined features, the explicit integer-to-pointer conversion is intended to have that effect. So, you'd do it as follows

Deleting a null pointer [duplicate]

放肆的年华 提交于 2019-12-08 20:38:11
问题 This question already has answers here : Closed 8 years ago . 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 null pointer, so what is the point of this check? 回答1: delete will check if the pointer is NULL for you, so you're right that the check isn't needed. You might also see that some people set the pointer to NULL after it's deleted so that you don

ANDROID STUDIO Can't access objects in fragment_main.xml

梦想与她 提交于 2019-12-07 18:51:55
问题 I have a simple Android app. The layout folder shows an activity_main.xml file and a fragment_main.xml file. In that fragment.xml file I have placed a button that I've named buttonTest. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"

Whats causing this NullPointerException in AWT-EventQueue-0?

∥☆過路亽.° 提交于 2019-12-07 18:37:09
问题 The Program: A simple Simulator to learn the very basics of Java. The user can input his own code in a supplied editor, which moves players across a field. This code is executed in a separate thread. Aside from this current issue the program works fine, this error popped out of the blue and did not appear before. The Problem: For some reason and in random time intervals the player throws the exception seen below. It does not matter what action the player has performed, as this also shows up

Why doesn't std::string take a null pointer?

我是研究僧i 提交于 2019-12-07 18:16:08
问题 I recently passed a null pointer to a std::string constructor and got undefined behavior. I'm certain this is something that thousands or tens of thousands of programmers have done before me, and this same bug has no doubt crashed untold numbers of programs. It comes up a lot when converting from code using char* to code using std::string , and it's the kind of thing that is not catchable at compile time and can easily be missed in run time unit tests. What I'm confused about is the reason

Why does gorm db.First() panic with “invalid memory address or nil pointer dereference”? [duplicate]

∥☆過路亽.° 提交于 2019-12-07 01:01:02
问题 This question already has answers here : How to use global var across files in a package? (2 answers) Closed yesterday . I can't figure out if I've done something silly or if I've found a bug in gorm. While I'm very well aware of what "invalid memory address or nil pointer dereference" means, I am completely mystified as to why it appears here. In short, I call db.First() and I receive a panic for no obvious reason. The relevant bits of my code: package main import ( "fmt" "github.com/gorilla

ANDROID STUDIO Can't access objects in fragment_main.xml

寵の児 提交于 2019-12-06 10:21:20
I have a simple Android app. The layout folder shows an activity_main.xml file and a fragment_main.xml file. In that fragment.xml file I have placed a button that I've named buttonTest. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical

Why doesn't std::string take a null pointer?

只谈情不闲聊 提交于 2019-12-06 01:54:12
I recently passed a null pointer to a std::string constructor and got undefined behavior. I'm certain this is something that thousands or tens of thousands of programmers have done before me, and this same bug has no doubt crashed untold numbers of programs. It comes up a lot when converting from code using char* to code using std::string , and it's the kind of thing that is not catchable at compile time and can easily be missed in run time unit tests. What I'm confused about is the reason for specifying std::string this way. Why not just define std::string(NULL)=="" ? The efficiency loss

Android - Dealing with a Dialog on Screen Orientation change

依然范特西╮ 提交于 2019-12-05 17:39:20
问题 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 some XML data and then use a dialog to display the info. I have basically followed it exactly but changed the variables to suit my own XML schema as follows: @Override public Dialog onCreateDialog(int id) { switch(id) { case (SETTINGS_DIALOG) : LayoutInflater li = LayoutInflater.from(this); View

Is printing a null-pointer Undefined Behavior?

我的梦境 提交于 2019-12-04 01:28:30
问题 When studying the sample code for this question I had assumed it was Undefined Behaviour which was preventing subsequent uses of std::cout from printing. But it turns out that attempting to print a null pointer caused std::ios_base::badbit and std::ios_base::failbit to be set in its stream state which was the real cause for its being non-operational. Because of this, I am now curious if it really is Undefined Behaviour to (attempt) to print a null-pointer. So here are my questions: Is it