Put value in structure pointed by a void 
Author Message
 Put value in structure pointed by a void

Hi,

I'm trying to get a value in a structure pointed to
by a void. I tried all kind of type casting, but I
seem to miss the right one!

Any idea?

Thanks,
        Eelco

struct STRUCT1
{
        int Number;
        void *DriverPrivate;

Quote:
}

struct YABADABADO
{
        int YO1;
        int YO2;

Quote:
}

void main()
{
        struct STRUCT1 *APtrToAStruct;
        struct YABADABADO AnotherStruct;

        APtrToAStruct->DriverPrivate=&AnotherStruct

        // This is what I want :-)

        APtrToAStruct->DriverPrivate->YO1=-1;

Quote:
}



Mon, 27 Aug 2001 03:00:00 GMT  
 Put value in structure pointed by a void

Quote:

>         void *DriverPrivate;
> ...
>         int YO1;

> void main()

Save your buffers! The world is coming to an end!
Do not code "void main()" unless you want to invoke nasal daemons!

And for your case, you can use:

  *( (int *)(APtrToAStruct->DriverPrivate) ) = -1;

To cast (void *) to (int *) and then dereference it as (int).

--
  A file that big?
  It might be very useful.
  But now it is gone.



Mon, 27 Aug 2001 03:00:00 GMT  
 Put value in structure pointed by a void
Hi
you have a _POINTER_ named APtrToAStruct which points to nowhere.
(struct STRUCT1 *APtrToAStruct;)
Then you try to change structure which is pointed by that pointer.
Try
struct STRUCT1 AStruct;
struct STRUCT1 *APtrToAStruct = &AStruct;
Quote:

>Hi,

>I'm trying to get a value in a structure pointed to
>by a void. I tried all kind of type casting, but I
>seem to miss the right one!

>Any idea?

>Thanks,
> Eelco

>struct STRUCT1
>{
> int Number;
> void *DriverPrivate;
>}

>struct YABADABADO
>{
> int YO1;
> int YO2;
>}

>void main()
>{
> struct STRUCT1 *APtrToAStruct;
> struct YABADABADO AnotherStruct;

> APtrToAStruct->DriverPrivate=&AnotherStruct

> // This is what I want :-)

> APtrToAStruct->DriverPrivate->YO1=-1;
>}



Mon, 27 Aug 2001 03:00:00 GMT  
 Put value in structure pointed by a void

Quote:

>struct STRUCT1
>{
> int Number;
> void *DriverPrivate;
>}

>struct YABADABADO
>{
> int YO1;
> int YO2;
>}

>void main()
>{
> struct STRUCT1 *APtrToAStruct;
> struct YABADABADO AnotherStruct;

> APtrToAStruct->DriverPrivate=&AnotherStruct

> // This is what I want :-)

> APtrToAStruct->DriverPrivate->YO1=-1;
>}

DriverPrivate is a void *.  You want to cast it to a YABADABADO *.  No
problem, eh?  Change your last line to:

(struct YABADABADO *)(APtrToAStruct->DriverPrivate)->Y01 = -1;

Oh, and in case nobody else tells you (heh, heh), ***MAIN() DOES NOT RETURN
VOID!!!!!!  IT RETURNS INT!!!!!***  ;-)

--
Mike Smith.  No, the other one.



Mon, 27 Aug 2001 03:00:00 GMT  
 Put value in structure pointed by a void

Quote:

> (struct YABADABADO *)(APtrToAStruct->DriverPrivate)->Y01 = -1;

Test before posting!
---


Mon, 27 Aug 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. from void (void*) to void (_cdecl*) (void*)

2. Size of data pointed to by void *

3. what's the difference between void main(void) and int main(void)

4. difference between void foo(void) and void foo()

5. Identifying what a void* point too.

6. Identifying what a void* point too.

7. Returning a void value

8. passing a structure to a function using (void*)

9. Error: Void value not ignored as it ought to be

10. Void value not ignored as it ought to be

11. Void value not ignored as it ought to

12. Int86: Error in C ANSI: (DOS.H : Value of type void is not allowed)

 

 
Powered by phpBB® Forum Software