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
5
votes
6answers
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 ...
5
votes
3answers
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 ...
3
votes
4answers
114 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* ...
0
votes
2answers
43 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,...
7
votes
2answers
269 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 ...
6
votes
4answers
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 ...
2
votes
1answer
45 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: ...
4
votes
0answers
71 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 ...
5
votes
6answers
1k 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 ...
2
votes
1answer
44 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: ...
4
votes
0answers
60 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. ...
2
votes
2answers
147 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 ...
0
votes
1answer
33 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: ...
5
votes
0answers
93 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. ...
4
votes
3answers
932 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: ...
2
votes
2answers
53 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 ...
-1
votes
1answer
54 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 ...
0
votes
2answers
206 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 ...
4
votes
2answers
328 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 ...
1
vote
1answer
470 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 ...
2
votes
2answers
97 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. ...
2
votes
3answers
221 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 ...
2
votes
1answer
93 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 ...
6
votes
2answers
600 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 ...
1
vote
1answer
215 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? ...
0
votes
1answer
61 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 ...
1
vote
1answer
51 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 ...
1
vote
0answers
15 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 ...
1
vote
2answers
394 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 ...
7
votes
3answers
612 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. ...
-1
votes
1answer
76 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 ...
1
vote
1answer
296 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: <...
3
votes
1answer
287 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: ...
-1
votes
1answer
57 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 (...
4
votes
1answer
120 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 ...
8
votes
1answer
555 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 ...
4
votes
1answer
109 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 ...
2
votes
0answers
44 views

Using std::function to write a function that returns a function

Our C++ professor told us to practise the use of std::function, lambda and pointers to functions. He asked us to: Write the function ...
2
votes
0answers
460 views

C# class to dump the memory of a process in several formats

I made this because I couldn't find any good C# classes/libraries that allow you to dump the contents of a process' memory into a file or a byte array. I haven't tested this on 32 bit systems but it ...
0
votes
1answer
126 views

Implementing a binary search tree using std::unique_ptr

I have implemented a binary search tree with 2 operations to begin with. I have tried to implement it using the best practices I could think of. Overall, I am happy with the implementation. But, I ...
6
votes
2answers
146 views

Simple C++ Test class with rule of 5

It has been a long time I used c++. So I brushing over concepts for interview preparation. Can you please help me with code review? If you have any observations/bugs/alternatives please point out. For ...
5
votes
3answers
94 views

Add two digit strings and return the result as string

I haven't done C in a while. This looks like a simple problem to start. Leetcode problem 415 Given two non-negative integers num1 and ...
0
votes
1answer
209 views

Using unique_ptr in FreeRTOS

I am trying to implement smart pointers for our project. We're using FreeRTOS which is written with a C API so it was quite a challenge to implement sending smart pointers around but somehow I managed ...
3
votes
2answers
78 views

String input and split functions in C

I've some functions targeted to simplify working with strings in some of my other projects. I'd like feedback on this code and whether or not the implementation is efficient and memory safe. I work ...
-2
votes
1answer
57 views

Smart pointer class implementation

I decided to implement a simple smart pointer class in C++ name my_pointer. Please review this code. ...
4
votes
0answers
41 views

Using UnsafeMutableRawPointers with Metal buffers in Swift

I've some Metal buffers which I populate with geometry data. Most data consists of Floats, but the buffer also contains custom structs for the tessellation stage. I ...
4
votes
1answer
65 views

C pointer based growable stack rev2

Following on from my previous question: C pointer based growable stack I have made some improvements (hopefully!) based on the very helpful comments and suggestions. I have checked that the stack can ...
7
votes
3answers
1k views

C pointer based growable stack

This is my first attempt at writing a C program, it a generic stack that can grow accordingly. It appears to work correctly, however I am worried that is just a fluke and I could be doing something ...
0
votes
0answers
32 views

Evaluating a Definite Integral, kindly check

The code below does not deal with any numerical-integration or anything related to it — just the basic rule in evaluating a definite integral of the form Ax^2 + Bx + C. I would love to hear from you ...

1
2 3 4 5
7