Is there a way to get the size of a three-dimensional vector using pointer notation?

77 Views Asked by At

I need to do something like this:

sizeof(int[width][height][8])

but unfortunately in c89 (the standard i have to use) this notation is forbidden, is there any way to do the same thing but using pointer notation?

Here's the error i get

It works fine in c99 but not in c89

1

There are 1 best solutions below

0
On BEST ANSWER

You can write this instead:

(sizeof(int) * (width) * (height) * 8)

Make sure you put the sizeof(int) first to force width and height to be converted to size_t and avoid a potential integer overflow on width * height * 8 if width and height have int type.