Cannot convert 'uint8_t (*)[160]' {aka 'unsigned char (*)[160]'} to 'uint8_t**' {aka 'unsigned char**'}

I try to make a pointer to a array uint8_t storeAddress [160]. But the compiler is compaining and I do not know why

#include <arduino.h>

uint8_t storeAddress [160];
int n =0;
uint8_t deviceAddress [8];
void ifAddressNew(int *nBezet, uint8_t address [], uint8_t *storeAddress[] ) {

}

void setup() {
// put your setup code here, to run once:

ifAddressNew(&n, deviceAddress, &storeAddress );

}

void loop() {
// put your main code here, to run repeatedly:

}

Arduino:1.8.13 (Windows 10), TD: 1.53, Board:"ESP32-WROOM-DA Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None"

C:\Users\Gebruiker\Documents\Arduino\ThermostaatValidated_V1\sketch_jun14a\sketch_jun14a.ino: In function 'void setup()':

sketch_jun14a:13:35: error: cannot convert 'uint8_t ()[160]' {aka 'unsigned char ()[160]'} to 'uint8_t**' {aka 'unsigned char**'}

ifAddressNew(&n, deviceAddress, &storeAddress );

                               ^~~~~~~~~~~~~

C:\Users\Gebruiker\Documents\Arduino\ThermostaatValidated_V1\sketch_jun14a\sketch_jun14a.ino:7:62: note: initializing argument 3 of 'void ifAddressNew(int*, uint8_t*, uint8_t**)'

void ifAddressNew(int *nBezet, uint8_t address [], uint8_t *storeAddress[] ) {

                                                 ~~~~~~~~~^~~~~~~~~~~~~~

exit status 1

cannot convert 'uint8_t ()[160]' {aka 'unsigned char ()[160]'} to 'uint8_t**' {aka 'unsigned char**'}

Why not simply

uint8_t *storeAddress

?

(For both)

1 Like

That give the same result
#include <arduino.h>

uint8_t storeAddress [160];
int n =0;
uint8_t deviceAddress [8];
void ifAddressNew(int *nBezet, uint8_t address [], uint8_t *storeAddress ) {

}

void setup() {
// put your setup code here, to run once:
ifAddressNew(&n, deviceAddress, *storeAddress );
}

void loop() {
// put your main code here, to run repeatedly:

}
Arduino:1.8.13 (Windows 10), TD: 1.53, Board:"ESP32-WROOM-DA Module, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None"

C:\Users\Gebruiker\Documents\Arduino\ThermostaatValidated_V1\sketch_jun14a\sketch_jun14a.ino: In function 'void setup()':

sketch_jun14a:13:35: error: invalid conversion from 'uint8_t' {aka 'unsigned char'} to 'uint8_t*' {aka 'unsigned char*'} [-fpermissive]

ifAddressNew(&n, deviceAddress, *storeAddress );

                               ^~~~~~~~~~~~~

C:\Users\Gebruiker\Documents\Arduino\ThermostaatValidated_V1\sketch_jun14a\sketch_jun14a.ino:7:62: note: initializing argument 3 of 'void ifAddressNew(int*, uint8_t*, uint8_t*)'

void ifAddressNew(int *nBezet, uint8_t address [], uint8_t *storeAddress ) {

                                                                                 ~~~~~~~~~^~~~~~~~~~~~

exit status 1

invalid conversion from 'uint8_t' {aka 'unsigned char'} to 'uint8_t*' {aka 'unsigned char*'} [-fpermissive]

Dit rapport zou meer informatie bevatten met
"Uitgebreide uitvoer weergeven tijden compilatie"
optie aan in Bestand -> Voorkeuren.

ifAddressNew(&n, deviceAddress, storeAddress );

presumably you understand what a pointer is
that char is a byte, the same as uint8_t
that the symbol for an char array is the same as a pointer to a c-string
and that *storeAddress[] is referring to an array of pointers, not simple a c-string (array of chars)

uint8_t storeAddress [160];
uint8_t deviceAddress [8];
int     n;

void
ifAddressNew (
    int     *nBezet,
    uint8_t *address,
    uint8_t *storeAddress )
{
}

void setup()
{
    ifAddressNew (&n, deviceAddress, storeAddress);
}

void loop() {
}

@jnivard before you write another post, read this and post your code properly with code tags.

Thank
as I understand it now:
1-storeAddress in the function call is a pointer to uint8_t storeAddress [160] it is marked by a * in the declaration of the function. I can update the array storeAddress [160] from within the function call.
2-What I not understand why I need the & before the n in the function call

Because the function expects a pointer.
n is a non-array, so you have to explicitly supply an address

arrays can be describe several ways.

like any variable, such as 'n', the address can be specified using '&': &n or &array [0]. but array is the same as &array [0].

An array is an array. It's a specific datatype. Typically, it's when the array's name is used in a function call that it can decay to a pointer.

There is one subtlety to be aware of. If your array is say:

int array[10];

then (when used in a function call) 'array' and '&array[0]' both decay to a pointer-to-integer pointing to the first element of the array.

However, '&array' decays to a pointer-to-an-int-array-of-size-10 (a specific datatype) pointing to the array. So in the code below, the third function call causes a compiler error because the datatype is incorrect:

void function(int *a) {
}

void setup() {
  int intArray[10];
  function(intArray);
  function(&intArray[0]);
  function(&intArray)
}

void loop() {
}
sketch_jun14a:9: error: cannot convert 'int (*)[10]' to 'int*' for argument '1' to 'void function(int*)'
   function(&intArray)
                     ^
cannot convert 'int (*)[10]' to 'int*' for argument '1' to 'void function(int*)'

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.