Float,double,int

This is a discussion on Float,double,int within the C Programming forums, part of the General Programming Boards category; Hi, A short question: Is there any way to find what kind of data is stored in a void*? I've ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    30

    Float,double,int

    Hi,

    A short question: Is there any way to find what kind of data is stored in a void*?

    I've assigned the value of a double to void* p, but sometimes a I have to use int or float. Please advise..

    Any ideas or suggestions?

    Thanks!
    Best Regards,

    Bill

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Is there any way to find what kind of data is stored in a void*?
    Yes, read your source code.

    You can't deference a void pointer.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        void *vp;
        float f = 1.1;
        float *fp;
        
        vp = &f;
        fp = vp;
        *vp = 1.2;  /* Illegal */
        *fp = 1.2;  /* Legal */
        return(0);
    }
    Does this help?

    [edit]Beat!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

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