Welcome, Guest. Please login or register.

Author Topic: sizeof (*VarPtr) possible ?  (Read 5312 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
sizeof (*VarPtr) possible ?
« on: January 30, 2007, 05:52:21 PM »
It seems that sizeof() works only with variable names themselves (or their types) but doesn't accept using a pointer to get the size of the variable pointed to. Any substitute for this ?
Goal is to use the sizeof result in a macro that accepts, among other things, a pointer to the variable. So I want it to be as short as possible and was trying to find a way to give the variable's size and ptr in one go (just give the pointer and the macro would get the size).

:pint:
P.S.
This is to improve the syntax of that general saver library I'm doing....
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
Re: sizeof (*VarPtr) possible ?
« Reply #1 on: January 30, 2007, 06:21:05 PM »
@Kronos
No, I was expecting the compiler to assume (compile-time of course) that sizeof (*VarPtr) would be the same as sizeof (Var), simply because it's logic. This is assuming that Var is the variable VarPtr points to.

@neuroflip
"...why don't you call sizeof() using the expected type that pointer points to?"

Because the goal is to make a syntax for a macro as short as possible. If the compiler understood sizeof (*VarPtr) I could simply pass VarPtr to the macro and it would be able to use VarPtr and the size of Var from it. Since it doesn't I need to pass 2 arguments: VarPtr and sizeof (Var), or VarPtr and Var ( in wich case the macro would get sizeof (Var) internally).
\\"We made Amiga, they {bleep}ed it up\\"