structured data with some missing members that i would like to treat as a zero when data goes into a function. i can declare a new variable with value zero and reference that with the pointer, but it feels sloppy. any way to put a 0 value in? compiler won't let me put & in front of 0, and without it, the address gets returned. thx.
see row 2 column 2:
uint32_t one = 1;
uint32_t two = 2;
uint32_t three = 3;
typedef struct
{
uint32_t *colum1;
uint32_t *column2;
uint32_t *column3;
}
DATA;
DATA data[]=
{
{&one, &two, &one},
{&three, 0, &two}
};
void setup() {
Serial.begin(9600);
Serial.println(*data[0].column2);
Serial.println(*data[1].column2);
}
void loop() {
}
If you initialize it to NULL (which I think is the same as '(void *)0'), you can check to see if the pointer is valid before using it. Maybe like this:
uint32_t one = 1;
uint32_t two = 2;
uint32_t three = 3;
typedef struct
{
uint32_t *column1;
uint32_t *column2;
uint32_t *column3;
}
DATA;
DATA data[]=
{
{&one, &two, &one},
{&three, NULL, &two}
};
void setup()
{
Serial.begin(9600);
while(!Serial);
Serial.println(*data[0].column2, HEX);
if( data[1].column2 == NULL )
Serial.println( "NULL" );
else
Serial.println(*data[1].column2, HEX);
data[1].column2 = &two;
if( data[1].column2 == NULL )
Serial.println( "NULL" );
else
Serial.println(*data[1].column2, HEX);
}
void loop()
{
}
THANK YOU !!
i played with NULL, but i was trying to dereference the value of NULL in the IF statement. this worked great
NULL was a catch all for 'empty value' in C and can still be used.
C++11 corrected this catchall by introducing a new keyword to serve as a distinguished null pointer constant: nullptr. It is of type nullptr_t, which is implicitly convertible and comparable to any pointer type or pointer-to-member type. It is not implicitly convertible or comparable to integral types, except for bool.