Questions tagged [pointer]

A variable in C/C++ which stores the type and location of data in memory.

There's an old programmer's saying:

"The problem with C is that it is too easy to shoot yourself in the foot.
With C++ it is much harder - but when you do, you lose your whole leg!"

Most of the problems have to do with C/C++ pointers, and people not fully understanding how to use them.

Links

  • Here's a basic description on pointers, going to the very beginning.
97 questions
12
votes
4 answers

Why is it considered bad practice to use the 'new' keyword in Arduino?

I previously asked this question: Is it required to delete variables before going to sleep? On that question, @Delta_G posted this comment: ... Really on a microcontroller I would create the object in a smaller scope and try to do everything in my…
Tono Nam
  • 966
  • 1
  • 10
  • 22
12
votes
2 answers

Why can I not use pointers instead of array with PROGMEM?

I'm currently changing some libraries to use flash instead of RAM for string storage so that I do not run out of SRAM on a project. Some strings in the library are declared in this manner: const char *testStringA = "ABC"; This is different to how I…
Cybergibbons
  • 5,420
  • 7
  • 34
  • 51
11
votes
2 answers

Are function pointer assignments atomic in Arduino?

The following snippets are from TimerOne library source code: // TimerOne.h: void (*isrCallback)(); // TimerOne.cpp: ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a user defined function supplied by attachInterrupt { …
Joonas Pulakka
  • 350
  • 2
  • 11
6
votes
1 answer

Is there any working analogue to the pair std::function and std::bind in Arduino?

Both ArduinoSTL and StandardCplusplus don't support them. They implement the version that is compatible with c++03 (not c++11). This functionality is handy when you design libraries that work with callbacks. And you do need them, if your Arduino…
Adam Ryczkowski
  • 279
  • 1
  • 5
  • 16
6
votes
2 answers

User callback functions

I want to write a class that allows the user to attach his own function to a member function that listens for messages coming from a wireless module, so that the user's function can be called depending on the message. I am thinking about using…
Vasil Kalchev
  • 293
  • 1
  • 2
  • 12
5
votes
3 answers

Works with gcc, not with Arduino. error: taking address of temporary array

I need to hard code 8 byte addresses into char arrays of length 8. This must be done many places in my code (in function scope), so I have tried to come up with a one-liner. The following works perfectly in C when compiling with gcc. char…
Mads Skjern
  • 1,145
  • 3
  • 13
  • 23
3
votes
1 answer

writting to buffer from serial input

Can some one explain this behaviour please, i have the following code byte buffer[512]; byte block; byte len; Serial.setTimeout(60000L) ; // wait until 20 seconds for input from serial // Ask personal data: Family name …
DevilWAH
  • 143
  • 5
3
votes
1 answer

ArduinoJSON v6 - Passing buffer as function parameter

I'm new to ArduinoJSON - so perhaps it is a newbie's question.... but I wish to pass a StaticJsonDocument into a function as a parameter ( later on it should be implemented in a library ). exmaple below shows test_1 what I wish to obtain, but by…
guyd
  • 1,049
  • 2
  • 26
  • 61
3
votes
1 answer

How do string pointers work in Arduino?

To the best of my understanding, when I declare String s = "This is a string."; what happens is that space is allocated on the stack for a pointer which points to some String object which internally contains a char array. My confusion stems from…
Samuel S
  • 33
  • 4
3
votes
1 answer

Using pointers with Arduino

I am learning about pointers. I was wondering how the memory address is defined in programming. I get different outputs depending on the format I choose for memory address. So I was wondering if it is correct to assume that the format of the memory…
Jack
  • 143
  • 1
  • 2
  • 6
3
votes
1 answer

sending ctrl-z in a struct?

I have a set of buttons wired to an arduino leonardo that are meant to send either single keystrokes to a computer "a, b, c..." etc, or a key sequence like ctrl+z (to perform an undo command.) Effectively this is a little usb keyboard with pre…
sylcat
  • 65
  • 6
2
votes
0 answers

Program crashes when calling external library code via function pointer

I've written a user library for the Pi Pico that uses the TaskScheduler library to abstract timing away from the user. The user provides a function in their sketch which the library calls periodically via function pointer passed in the…
Joe of Loath
  • 157
  • 3
2
votes
1 answer

How to pass Encoder object to constructor of a different class

I am trying to create a class (Arm) that controls an arm. The arms have 2 motors, each with an encoder, so I pass 4 integers for the pins and I am trying to pass 2 pointers (one for each encoder object). the .ino file is: #include "Arm.h" #include…
2
votes
1 answer

Converting c string to integer to unsigned char

I'm grappling with types between two different libraries. The gist is that I'm using the ArduinoWebsockets library to receive information coming from my API that I then want to render out to an LED matrix. An example message would look like…
Chris Schmitz
  • 357
  • 6
  • 18
2
votes
2 answers

Issues converting an uint32_t into a char*

I'm using a capacitive touch sensor that as 12 touch points and stores it's state data as a binary number. I want to take that state, add a bit of data onto the front, and then send it up to a server via websockets. I'm using the Arduino Websockets…
Chris Schmitz
  • 357
  • 6
  • 18
1
2 3 4 5 6 7