2022 Developer Survey is open! Take survey.

Questions tagged [pointers]

In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.

Filter by
Sorted by
Tagged with
0 votes
0 answers
10 views

Closing handles in Powershell; handling partial cases in a DRY fashion

Powershell contains no "goto" statement which is the normal way C++ code closes or 'frees' handles at the end of functions that use several or many handles (pointers). When interating with ...
user avatar
  • 109
3 votes
1 answer
48 views

display processes children

The following program uses a parent program to determine the PIDs of multiple child processes. A function is called to return them to a dynamic vector (with the children's pids, but also the elements ...
user avatar
  • 179
1 vote
0 answers
125 views

Inheriting from a JSON converter class with schema definition through constructor

I wanted to convert C++ data structures to JSON with little code. More specifically, I wanted to convert C++ data structures to nlohmann JSON representation. Project context: The goal is to use this ...
user avatar
0 votes
2 answers
70 views

Slice function for C

I am trying to create a non-generic slice function. I want a 'view' not a copy. The scan_from arg is so that successive calls ...
user avatar
  • 503
2 votes
1 answer
44 views

std::unique_ptr adapter class template for libgit2 objects

I'm working on a personal project to build an open-source gui for git. I'm hoping to learn a lot from the project, and maybe produce something useful for folks as I do. I'm making use of libgit2 to ...
user avatar
1 vote
2 answers
129 views

Improvement suggestions to my shared_ptr and weak_ptr implementations

Below is the entire code. I appreciate if, someone with more C++ experience can suggest if this can be improved further and if you notice any issues. controlblock.hpp ...
user avatar
  • 135
10 votes
0 answers
175 views

Low Level VBA Hacking - making Private functions Public

NEW: Download demo files Not sure what to title this - essentially, inspired by RubberDuck's unit test engine, I've created a way to call private methods of standard modules in VBA. It also lets you ...
user avatar
  • 1,998
2 votes
2 answers
53 views

C library implementing binary trees

This is my first attempt at writing a library in C. I have only included tree creation and in-order traversal function for now, but will expand to have more functions soon. I have three files, ...
user avatar
2 votes
1 answer
136 views

red black tree implementation in cpp

I am learning algorithms and trying to implement them in c++, I have chosen to try to implement a red-black tree due to its self-balancing properties and its ability to stop the worst case of O(n) ...
user avatar
3 votes
2 answers
445 views

Simple string manipulation in C (for small microcontrollers)

Although I have long experience of other languages, I've not used C until playing around with microcontrollers using the Arduino IDE. I'm a bit uncomfortable with my use of pointers in conjunction ...
user avatar
5 votes
2 answers
547 views

C++ Garbage Collector - Simple Automatic Memory Management

I made a general smart pointer which fixes the problems of loops between std::shared_ptr's. While use is simple, I feel that my code is inefficient and clumsy. Here ...
user avatar
3 votes
2 answers
62 views

Testing MRU-list vs. standard list

The task is to test the the benefits of a Move-To-Front Linked List vs. a standard Linked List. It was also meant to practice inheritance and pointers. The standard functionality is in ...
user avatar
  • 235
6 votes
6 answers
2k views

Left Shift/ Right Shift an array in C

I am trying to implement a Left shift/ Right Shift on arrays. I was able to accomplish this using double loops. Can the efficiency be improved? This is the working code for LeftShift/RightShift which ...
user avatar
  • 71
5 votes
3 answers
1k views

FizzBuzz, but with provided start and end of sequence, results stored in array, and a separate function to convert integers to strings

To learn C, I'm doing the traditional FizzBuzz challenge with extra restrictions: The start and end of sequence is provided by the user Instead of directly printing the results, the results must be ...
user avatar
  • 729
3 votes
4 answers
151 views

Improving my implementation of a unique_ptr - PPP Stroustrup book

This question is an improvement of this one here: Implementing a unique_ptr - PPP Stroustrup exercise Here's my new code, following the suggestions by @JDługosz. I agree with the fact that T* ...
user avatar
0 votes
2 answers
66 views

Implementing a unique_ptr - PPP Stroustrup exercise

I'm doing the following exercise from PPP - Bjarne Stroustrup, Chapter 19, ex.10. Implement a simple unique_ptr supporting only a constructor, destructor,...
user avatar
7 votes
2 answers
638 views

Hack machine language assembler as required for project 6 of Nand2Tetris

This is the implementation of the Assembler required to parse source code written in the Hack Machine Language and output it to a 16-bit binary file. After writing one go in Swift, I decided I wanted ...
user avatar
6 votes
4 answers
1k views

Minimum of two floating-point numbers

I'm learning C and I just had the exercise to write a function that checks for the lower one of two floating-points. So I thought, I either could use pointer and also return the pointer of the lower ...
user avatar
2 votes
1 answer
48 views

Linked list - append, insert, print

I am a beginner in C and am learning linked lists. I have made a program to implement a linked list, allowing certain operations on the linked list. There are 3 functions: ...
user avatar
4 votes
0 answers
116 views

A safe type-erased Fn Pointer in rust that can be used to call associated and regular function

I am implementing a callback method to replace the use of generics. For maximum performance, it is not allowed to use Box and I also don’t want to use ...
user avatar
  • 141
5 votes
6 answers
2k views

Implementation of itoa which allocates the string

This is my implementation of itoa() (Integer to Alpha), which converts an integer to a string. Memory management and optimization is important. The caller is not ...
user avatar
  • 61
2 votes
1 answer
47 views

Decoupling receiving data and processing data by passing callback and shared_ptr

Sorry for my poor English. I want to decouple receiving data and processing data, this is the demo code: ...
user avatar
  • 145
4 votes
0 answers
95 views

Possible optimization for finding small bitmap in large bitmap in C# without unsafe code?

Background I am creating a tool to locate a small bitmap in a large bitmap by comparing each pixel. Since I am by far no professional programmer, I was searching for some code snippets and found this. ...
user avatar
  • 41
2 votes
2 answers
355 views

Storing a copy of unique_ptr

When one writes c++ code to manipulate LinkedLists, Trees, etc. one creates a tmp pointer that points to the start/root and changes that pointer as one traverses along. What would be the equivalent ...
user avatar
0 votes
1 answer
37 views

Inquiring possible alternatives to custom hierarchy-aware smart pointer

I have a medium sized project that uses a class hierarchy that essentially boils down to: ...
user avatar
  • 117
6 votes
1 answer
258 views

Implementation of std::atomic<std::shared_ptr<T>> for C++20

As you may know, C++20 has added std::atomic<std::shared_ptr<T>> specialization to the standard, but sadly, most compilers have not implemented it yet. ...
user avatar
  • 285
4 votes
3 answers
1k views

De-/Serialization of structs representing TCP messages

I wrote two template functions to serialize and deserialize structs representing messages to be sent and received via a TCP socket: ...
user avatar
2 votes
2 answers
73 views

Merge Sort for Linked List Criticism in C

I previously implemented a Merge Sort for arrays, so after fixing up my code for the array-based merge sort I have now implemented a merge sort for a basic singly-linked list data structure which only ...
user avatar
  • 403
-1 votes
1 answer
77 views

Scanning multiple strings in one line to a pointers array in C [closed]

I'm trying to write a code for a function that takes an empty array of pointers and its length n. And scans n strings of max length of MAX_LEN (a defined constant) until a new line is given by the ...
user avatar
  • 171
0 votes
2 answers
211 views

C++ Simple Shared Pointer Implementaion

I wrote an implementation of a shared pointer. I would like a review of it. It seems to work, but running it through Valgrind shows that that it leaks memory somewhere in my tests, but I don't know ...
user avatar
  • 103
4 votes
2 answers
359 views

"observer pointer" meant to stay updated when the pointed object is moved in memory

I wasn't sure about how to name it, maybe "follow_ptr", "self_updating_ptr", or "stalking_ptr" or something on those lines. For now it's called Identifier. What I'm ...
user avatar
  • 207
2 votes
1 answer
1k views

dynamic_pointer_cast for std::unique_ptr

dynamic_pointer_cast is only implemented for std::shared_ptr, I need it for unique pointers. The wrinkle is that dynamic_casting ...
user avatar
2 votes
2 answers
119 views

Reference-counted smart pointer in C

About I've been experimenting with gcc's __cleanup__ attribute, and thought it'd be a great fit for a memory-safe smart pointer for C. This is the implementation. ...
user avatar
2 votes
3 answers
306 views

Tic-Tac-Toe game in Java

I had to write a TicTacToe game as an assignment for class & the last program I wrote used a few continues here and there. When I asked for a peer code-review I was informed that I should use ...
user avatar
2 votes
1 answer
109 views

C++ wrapper for font opaque pointer

I'm creating a class which has a raw pointer member which comes from a C function. In order to make it RAII approved, I just created a method free() that is called ...
user avatar
  • 23
6 votes
2 answers
911 views

shared_ptr and make_shared implementations (for learning)

Recently, I've been going through Scott Meyer's Effective Modern C++ and found the discussion on shared_ptr really interesting. I also watched Louis Brandy's ...
user avatar
  • 123
1 vote
1 answer
447 views

C++ shared pointer wrapper for lazy initialization

I have written a very simple wrapper around std::shared_ptr that supports lazy initialization. Do you see any problems? ...
user avatar
0 votes
1 answer
96 views

Generic stack implementation in C

I haven't separated the stack code into its own header and source yet, this is just a proof of concept for now. Haven't chosen better function names yet because I ultimately want to integrate this ...
user avatar
  • 215
1 vote
1 answer
57 views

Pointers and arrays

I just started to learn pointers, so I'm interested if I used them correctly in this task where I check if the absolute value of the greatest element in an array is two times greater than the absolute ...
user avatar
  • 15
1 vote
0 answers
17 views

Using (templated) function-scope static address as Unique ID [closed]

typedef const bool* const TypeID; template<typename> TypeID TypeIdOf() noexcept { static const bool idLoc(0); return &idLoc; } I'm using ...
user avatar
2 votes
2 answers
1k views

C++ Shared_Ptr implementation

I reinvented a c++ smart pointer, shared_ptr to be precise. It is meant for practice purpose and does not attempt to replace the standard implementation. To the ...
user avatar
6 votes
3 answers
691 views

Double Linked List with smart pointers: problems with insert method

I'm trying to implement a Templated Double Linked List, following Stroustrup's book "Principles and Practice using C++", Chapter 20.4. Instead of raw pointers, I want to use unique pointers. ...
user avatar
  • 161
-1 votes
1 answer
79 views

How to eliminate derefs?

Spoiler: Advent of Code 2020 Day 8 Your flight to the major airline hub reaches cruising altitude without incident. While you consider checking the in-flight menu for one of those drinks that come ...
user avatar
1 vote
1 answer
458 views

How to use smart pointers with SDL2 (SDL_RWops)?

I want to write read savefile function with smart pointers and SDL2. I have little expirience with smart pointers and just want to ask is my code good, correct and no memory leaks. this is my code: <...
user avatar
3 votes
1 answer
344 views

Maintain a list of contacts in C

I have a function that gets a string and prints it as a message. Then, it reads the text from stdin, saves it in a pointer and sends it back: ...
user avatar
  • 181
-1 votes
1 answer
64 views

Use of pointers in C in Erasthenes sieve program [closed]

I made the following code in C, which is supposed to create a list of booleans $n + 1$ long, such that the $i$'th element is true if $i$ is prime and $i$'th element is false if $i$ is not prime (...
user avatar
4 votes
1 answer
140 views

Extreme use of pointers in adjacency list graph construction?

Playing around with pointers in C++, implemented an adjacency list graph. Am I going too far/extreme trying to place data onto the heap? graph.h ...
user avatar
  • 375
9 votes
1 answer
688 views

Using smart pointers to construct Binary Search Tree

I have three main questions: Am I using std::unique_ptr correctly here? Using std::move and ...
user avatar
  • 375
3 votes
1 answer
748 views

Stateful function pointer for passing C++ capturing lambdas / std::functions to C style callbacks

...
user avatar
  • 101
4 votes
1 answer
121 views

Switching first names with surnames

The objective is to get a list of number and then switch the last person surname with the first person surname; when I type '$' it do the changes and finish the program! (POINTERS and DYNAMIC ...
user avatar
  • 49

1
2 3 4 5
8