sizeof(void *)*1

This is a discussion on sizeof(void *)*1 within the C++ Programming forums, part of the General Programming Boards category; Originally posted by FillYourBrain darksaidin you're confusing. you don't understand void *? * after a type is pointer notation. It ...

  1. #16
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Originally posted by FillYourBrain
    darksaidin you're confusing. you don't understand void *?

    * after a type is pointer notation. It means that you have a pointer to that type. in the case of void * it basically means it can be a pointer to anything really. sizeof(void *) will return 4. sizeof(int *) will also return 4. It's just the size that a pointer on a 32 bit system is.
    I already understood that, FillYourBrain.

    My problem at first was that I thought the * was always in front of the variable (and not behind the type) because there is no such thing as a pointer to a type but only pointers that can be used like variables of specific type.
    At least in OP. C obviously defines it the other way round:
    You define a new variable (which will be a pointer) of a type that [meaning "the type"] can be used to create pointers that can only point on a variable of that given type. ... which is a strange way of looking at it, but accurate. Only that this way of looking at it allows to have the * behind the type (which otherwise would make no sense) and not in front of the variable.

    If you never coded in Delphi you probably won't understand my problem here.

    Anyway, my problem has been solved, thanks to Cat explanation.

  2. #17
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Originally posted by golfinguy4
    Wow RoD, you learn fast.

    Self-made functions: Opinion
    Dude that was 9 months ago....

  3. #18
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Originally posted by darksaidin
    I already understood that, FillYourBrain.

    My problem at first was that I thought the * was always in front of the variable (and not behind the type) because there is no such thing as a pointer to a type but only pointers that can be used like variables of specific type.
    To expand, pointers ARE typed. For example:

    int * i;

    declares i, and says "i holds an address, and at that address lives an int". Similarly,

    MyClass * c;

    declares c, and says "c holds an address, and at that address lives an object of class MyClass".

    Of course, it is up to the programmer to make sure the pointer actually has the proper address. E.g. the programmer would have to make sure c held the address of a valid MyClass object before using c to do something with that object.

    Now, void * was added to C, it wasn't an original feature. The goal was to create a fully generic pointer type, and "void" was already a keyword. Further, it is not legal to create an instance of type void (i.e. the line "int i;" is OK but "void v;" is a compiler error). Because they already had the word "void" reserved as a keyword, and a "void *" was meaningless at the time, they made "void *" mean a special kind of pointer.

    void * v;

    declares v, and says "v holds an address, and something lives at that address but I don't know what that something is".

    In this way, a void * is the most generic kind of pointer. You can't do a lot with it, but you can convert any other pointer into a void * (automatically), and you can convert a void * to any other pointer (automatically in C, explicitly in C++).
    Last edited by Cat; 07-24-2003 at 01:42 PM.

  4. #19
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Sure, pointers can have a type, that much was clear
    I merely said that there are no pointers *to* a type (as said in one of the posts), meaning a pointer that points on a datatype.

    If I may add, it would have been a lot easier to read in OP:

    int *an_integer;
    var an_integer: ^integer;

    You can read it the way it is written: Variable an_integer is a pointer to an integer - they even used an arrow . Thats were my trouble originated from: Pointer to an integer. There is always a word behind the pointer symbol. void * lacks that - and right so, it's different in C because they used a "different logic". Both can make sense.

  5. #20
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    pointer to a type? That makes no sense as a type doesn't take up memory, therefore can't have an address.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #21
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    C/C++ usually works best if you read it backwards.

    E.g.:

    int * myPointer;

    "myPointer points to an int"

    This is especially helpful when dealing with constants:

    const int * p;

    "p points to an int that is constant". It's equivalent to:

    int const * p;

    "p points to a constant int"

    but is not the same as:

    int * const p;

    "p is a constant pointer to an int"

    and there is also:

    const int * const p; or int const * const p;

    "p is a constant pointer to an int which is const"/ "p is a constant pointer to a constant int"

    Get used to reading pointer stuff backwards, and you'll be fine

    And "pointer to a type", as was said, isn't technically correct. But a lot of people use it; it's just short for "pointer to an instance of a type" which would be more correct. It's like saying "pointer to int" -- it really means a "pointer to an instance of type int"
    Last edited by Cat; 07-24-2003 at 02:51 PM.

  7. #22
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Cat, that ROCKED!

    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  8. #23
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Originally posted by darksaidin
    Sure, pointers can have a type, that much was clear
    I merely said that there are no pointers *to* a type (as said in one of the posts), meaning a pointer that points on a datatype.
    That's what I was referring to. pointer that points to a datatype. Darksaidin seemed to be suggesting that OP (Object Pascal?) has pointers to datatypes themselves.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  9. #24
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Originally posted by RoD
    Dude that was 9 months ago....
    And how long has your first OpenGL tut been up there?

  10. #25
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Originally posted by FillYourBrain
    That's what I was referring to. pointer that points to a datatype. Darksaidin seemed to be suggesting that OP (Object Pascal?) has pointers to datatypes themselves.
    Nope I wasn't. At least I don't think I was.
    (I would skip the next paragraph if I were you. I just had to mention it )

    However, it's actually true. You can have pointers to certain types in Delphi: Classes ("object types"). Normally there isn't much use in pointing at them. You could do it in a dynamically linked DLL to import a class from the executable that linked the DLL, create new derived(w?) classes with that classpointer and than even "reimport" that new class back into the executable. It's a bit tricky and a few other conditions have to be met, i.e. you can't just go and use methods of the reimported class like you'd use normal methods, because they were not known at linktime. Either you use a baseclass in both files and define abstact methods to be overwritten by derived classes or you got to get the pointers to the new methods from the dlls classtable (which can get very messy)... ...

    Anyway, that wasn't the topic. There is no need to keep it bumped anymore. Thanks for all the replies, really helped me a lot!

  11. #26
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Originally posted by golfinguy4
    And how long has your first OpenGL tut been up there?
    Note sure exactly, it was back in january or febuary at least because i was out snowboarding the one day and that postponed the day they came out. Webmaster would know, but i wouldnt waste his time to make you happy.

    I dont get why you make a life out of attacking me dude.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help on pointer to VOID
    By dv007 in forum C Programming
    Replies: 19
    Last Post: 07-09-2002, 06:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21