I'm writing a function that receives data from a board through a pre-existing DAQ database. The function does some logic and printing on the data results. The type of data that is being sent to me from the database is in a struct formatted as:
typedef struct _ARINCWord{ uInt32 Label; uInt32 Ssm; uInt32 Sdi; uInt32 Parity; uInt32 Data; }ARINCWord; Sometimes, when accessing the contents of the struct, I get an address back instead of the expected value. This is because the database I'm working with preallocates memory if even one of the parameters was read through the board. I need a way to check and see if any of the contents of the struct contain memory addresses instead of the expected values.
I dont have too much background in C++ and pointer logic, just the basics, so this is out of my comfort zone. When I print the contents of the struct, I get back integers, even if some of the parameters are pointers. An example of the expected data is this:
RX port 1: Received word: Label=12 Data=22 Sdi=1 Ssm=2 Parity=0 and an example of a print where some of the parameters were not read properly is this:
RX port 1: Received word: Label=16253120 Data=22 Sdi=1 Ssm=58774128 Parity=0 Notice how some of the data points were read properly, but the Label and Ssm were not. The values for Label and Ssm appear to be memory addresses, but they simply print as integers. I need some way to check if each component of the struct is a proper value.
I'm unable to change the DAQ database, so I need to find some way to deal with the problem myself. I dont want to put code that says something like
if(word.Label > 1000){ //tell the code that this parameter is missing } because I might need a value greater than 1000 farther down the line.
Any help or pointers would be appreciated.
Edit: In response to some of the questions, I dont create the struct, the database creates the struct and fills it with the data that was read in. The printed text in my answer is me printing the contents of the struct.
As for a minimum reproducible example, Im not quite sure I can, because Im unable to mimic the code within the database. I dont have access to the whole database, and much of it im unable to share.
It looks like i'm getting an address back because the database was unable to read that specific datapoint. This happens very rarely but I need to be able to catch this edge case error.
Im mainly looking to see if there is a way to tell the difference between an int that represents an address vs an int that represents a number, which it appears there isnt.
ARINCWord? You might want to set it to an invalid value (Like all fields to-1) before reading and check for that.uInt32in both cases, there is no way to distinguish between a "real" value and a pointer.unsigned intvalue is a pointer or not. It's not something you can determine after the fact._ARINCWordis a reserved identifier. Defining it in a user program would result in undefined behaviour.