Questions tagged [pointers]
A pointer is a data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.
143 questions
2
votes
3
answers
186
views
API Design: Should I explicitly check for and throw on nullptr parameters if I have full control?
Say I have the following header
#ifndef WINDOW_HPP
#define WINDOW_HPP
// includes...
namespace window
{
struct Window
{
GLFWwindow *handle = nullptr;
};
struct ...
1
vote
7
answers
436
views
Is it possible to introduce Pointers to a weakly typed programming language?
Most weakly typed languages do not have a concept of a pointer. Instead, most of them use references. However, is it possible to introduce pointers to such a language.
From a naive point of view, to ...
0
votes
1
answer
84
views
Avoiding repeating code when assigning pointer addresses based on branch
I have the following code in C that reads data off a char array and makes decisions on what variables should some pointers point to.
char preset1[20];
char preset1Name[20];
int preset1Temp;
int ...
4
votes
2
answers
2k
views
Reference variable vs Alias
When I started programming, I learned what Pointers are in C++. In Java, references are variables which hold the address of an object. So conceptually it's a pointer, without the ability to directly ...
0
votes
1
answer
428
views
Implement Dependency Inversion in C with UML diagram
As per Robert C. Martin in Clean Architecture, he gives a simple UML diagram to illustrate Dependency Inversion.
To put it simply, HL1 initially referred to ML1 without interface to invoke F() ...
1
vote
4
answers
12k
views
C++: Is a pointer to a vector going to cause memory issues?
I started to write a function which had a pointer to a vector as a parameter so that it could modify that vector to output results (as the actual return value was an error code), when I started to ...
0
votes
1
answer
137
views
What design pattern (if so) did I apply? How can I further improve it?
Suppose I have a program.c that needs element_123 to do some operations, and element_123 can be accessed by including agent.h
/*program.c*/
#include "agent.h"
uint32_t element_123 = 0;
...
11
votes
3
answers
3k
views
What are the pros and cons of using a reference/pointer vs an ID
I'm writing in C++, but this problem applies to any language without GC and even to languages with a GC as well.
I have a structure in memory in which I create/add objects. The structure takes ...
-2
votes
2
answers
202
views
What is the correct use of -> operator when working with pointers?
I'm pretty new with C so I have encountered many doubts with pointers.
I've already search a lot about this but there are some things that still are not clear for me, and I also think this will help ...
1
vote
2
answers
2k
views
Should I always allocate QObject and derived classes to the heap?
I was in #Qt irc channel, and I showed a small snippet of my code in a style that I heavily rely upon. It looks like this:
/* Get Reply from Server */
QPointer<QNetworkReply> reply;
{
...
5
votes
1
answer
7k
views
Why do we need to specify the type of data a pointer will hold, if all pointers are the same [duplicate]
Why do we need to specify the type of the data whose address, a pointer will hold, if all pointers are the same.
Since all pointers store addresses.
Also, the amount of space a pointer will require in ...
0
votes
2
answers
2k
views
What is the safest practice in handling QWidget pointer lifespan in a QObject oriented environment?
Consider the following constructor:
NetworkTools::NetworkTools(QObject *parent) : QObject(parent)
{
view = new QWebEngineView();
view->setParent(parent); // Produces an error, shown below.
...
1
vote
2
answers
327
views
Setting a pointer to NULL on failure?
I've been modifying some code written by a previous employee and came across a function with the following signature:
BOOL WINAPI PrependPadding(
_In_ SIZE_T cbPadding,
_In_ SIZE_T cbRow,
...
-1
votes
1
answer
2k
views
Why is it possible to access an array out of bounds with negative indexes much further than with positive indexes?
I have written two small programs in which I declare a very small array.
Then I try to access values out of bounds.
The interesting thing I noticed that when I try to decrement the index I can ...
1
vote
1
answer
156
views
What kind of pointer bug is this specifically?
UncommentatedPannen's (pannenkoek2012) newest video describes a glitch in the Nintendo 64 game Super Mario 64, which allows an object to push Mario out of bounds, which isn't normally possible, by ...
4
votes
1
answer
2k
views
Should opaque pointers be pointers or types?
A common way to implement "PIMPL" in C is to do this:
typedef struct _Opaque Opaque;
Opaque* createOpaque();
void doSomething(Opaque *opaque);
Or:
typedef struct _Opaque* Opaque;
Opaque ...
-1
votes
1
answer
596
views
GO - How to define methods of named type?
In GO, rule is, methods can be defined only on named type and pointer to named type.
In C, below code, operations are defined on type(say List),
typedef struct List List; //list.h
typedef struct {
...
1
vote
1
answer
65
views
How to avoid fetching additional informations when instantiating objects
I'm creating an HTML5 game using javascript and have got some problems during the first instantiation of the objects of the scene.
Scenario
Self-written 2d game engine that supports multiple types ...
2
votes
5
answers
2k
views
What value does the byte pointed by null pointer have?
I know that long time ago computer scientists decided to treat all pointers to memory cell of address 0 as NULL. However, the memory cell at that address does exists after all, right? In that case, ...
8
votes
6
answers
5k
views
In C++; How big should an object [that will be transferred between functions] be before I consider delegating it to the heap?
In my day to day programming, I tend to use very few pointers, not only because I want to keep my code simple and error free, but because I assume that the programming that I do does not have any ...
9
votes
6
answers
2k
views
In C, is * an operator, or part of a type in a declaration?
In C, * is called the indirection operator or the dereference operator. I understand how it works when it is used in a statement. It makes sense to write *p or * p, considering that it is a unary ...
1
vote
2
answers
1k
views
Passing by refernce
I am trying to understand the ideas of pointers and references in C++. I am stuck with the following, what would be the specific behaviour in this case? I have a class like this:
class MyClass{
...
1
vote
1
answer
228
views
Static memory idiom
I am on a micro controller (which means I can only have static memory allocation) and I am trying to work with inheritance.....
Suppose I have a abstract class Image and an abstract class Font. An ...
4
votes
4
answers
1k
views
When should a function take a pointer for a collection to fill vs returning a pointer with a filled collection?
In C++ I frequently see these two signatures used seemingly interchangeably:
void fill_array(Array<Type>* array_to_fill);
Array<Type>* filled_array();
I imagine there is a subtle ...
3
votes
2
answers
4k
views
Is it possible to have pointers recursively point into themselves?
I have been learning C++ recently, and upon reading up on pointers I had a moment of thought.
I'm still attempting to grasp the very idea of pointers so excuse me if this doesn't make sense beyond ...