0

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

Enrico
  • 84
  • 1
  • 9
  • 1
    *c89 (the standard i have to use)* Hopefully that's a hardware restriction and not some brain-damaged artificial limitation. Otherwise why not restrict you to stone tablets and an abacus? – Andrew Henle Dec 04 '20 at 10:26
  • Don't post links to pictures of text but post text as text directly in the question. – Jabberwocky Dec 04 '20 at 10:41
  • Even if you figure out the `sizeof` (which is a simple matter of multiplication), you won't be able to declare a variable of that type anyway. – interjay Dec 04 '20 at 10:44
  • Your error is clearly stated by the compiler: this is forbidden. Understand it as impossible to achieve. If compilation passes, I am quite sure this will still lead to undefined behaviour. – A. Gille Dec 04 '20 at 13:00

1 Answers1

0

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.

chqrlie
  • 131,814
  • 10
  • 121
  • 189