0

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.

9
  • 3
    I would guess that they are just not being set, and you're just reading garbage. How are you reading an ARINCWord? You might want to set it to an invalid value (Like all fields to -1) before reading and check for that. Commented Sep 10, 2019 at 12:56
  • 1
    Check out the documentation for the database. If they really are dynamically allocating things and then type punning like this, they should provide some way to tell whether or not that happened for each parameter. Otherwise, since the type of each member is uInt32 in both cases, there is no way to distinguish between a "real" value and a pointer. Commented Sep 10, 2019 at 12:56
  • There is no meaningful way to tell if an unsigned int value is a pointer or not. It's not something you can determine after the fact. Commented Sep 10, 2019 at 13:01
  • _ARINCWord is a reserved identifier. Defining it in a user program would result in undefined behaviour. Commented Sep 10, 2019 at 13:02
  • 1
    Create a minimal reproducible example. Why do you think that "I get an address back instead of the expected value"? Commented Sep 10, 2019 at 13:04

1 Answer 1

2

What you are trying to do is impossible. You lost the original data type and now only have numbers. Just from the number value you cannot tell if it is really a number or a memory address. The idea to check if the value is larger than a certain limit might be the only sensible approach you have here (but as you found yourself this has problems too).

You could also try to actually read the value at the address indicated by the value you got. You can probably exclude anything that is not aligned to a multiple of 8 bytes (depending on the platform), but even if you can read a value it's not 100% sure that this address is really what was intended.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.