-
sizeof assertion problem
Hello,
In my program I would like to assert that the size of my array is what I told it to be as a precondition for a function.
The function is:
Code:
void getRow(char *token, char *input)
{
assert(sizeof(*input)==MAX+TERMINATOR);
}
- Note TERMINATOR is a constant = 1 for the null terminator.
So this assertion fails. My guess is that it's because the input points to only 1 char. I believe my guess is correct because
Code:
assert(sizeof(*input)==sizeof(char));
passes.
In the calling function input is not a pointer but a char array.
In the calling function this assertion works:
Code:
char input[MAX+TERMINATOR];
assert(sizeof(input)==MAX+TERMINATOR);
Is there a way to have an assertion like this in the getRow function or is it just not possible?
-
Not possible since input is a pointer, not an array.
-
-
If TERMINATOR is simply the number 1 then it's simply obscuring the meaning. Just say + 1.