home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,370 of 33,346   
   Seungbeom Kim to doug@dbassoc.com   
   Re: Casting from void*   
   23 Jun 11 14:41:53   
   
   e9f10825   
   From: musiphil@bawi.org   
      
   On 2011-06-22 15:53, doug@dbassoc.com wrote:   
   >   
   > I have a routine that gets passed a void* to a structure.  In the   
   > routine I cast it to the correct type, e.g.   
   >   
   > SomeFunc(void* pMsg) {   
   >  printf("Event = %d\n", static_cast(pMsg)-   
   >> Event);   
   > }   
   >   
   > If I am accessing many members of the structure the code looks pretty   
   > messy.  I can create a new pointer of the correct type and assign it   
   > the cast void*, but it seems like it shouldn't be necessary to create   
   > a temporary variable just for this purpose.  Is there some way to cast   
   > the parameter pMsg to the correct type?   
      
   You just explained why it may be necessary to create a temporary variable.   
   What potential drawbacks are you afraid of?   
      
   --   
   Seungbeom Kim   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca