We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

what is the difference between these two typedef/thread procedure declarations?

PMH4514
PMH4514 asked
on
Medium Priority
281 Views
Last Modified: 2010-04-01
what is the difference between:

typedef struct _MyData {
    int val1;
    int val2;
} MYDATA, *PMYDATA;


DWORD WINAPI ThreadProc( LPVOID lpParam )
{
      PMYDATA pData;
      pData = (PMYDATA)lpParam;
      //
}


and

typedef struct MYDATA{
      int val1;
      int val2;
} MYDATATYPE;

DWORD WINAPI ThreadProc( LPVOID lpParam )
{
      MYDATATYPE* pData = (MYDATATYPE*)lpParam;
      //
}


just different syntax?
Comment
Watch Question

Senior Software Engineer
Commented:
The first one is not portable because it's using a name that begins with an underscore (_MyData).
Names that begin with an underscore are reserved for the implementation IAW C++ standard.

Also the first one is less efficient since it first initialize the variable, and then it sets the value.

When possible, you should always try to declare and initialize the value at the same time.

If you're just asking about the typedef, there is no runtime differences, but I would recommend using the first typedef method (once you remove the underscore).

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
the 2nd is the way I have been doing it. The first I saw ont MSDN.  The first one becomes portable removing the underscore? You also mention the first is less efficient, so why would you recommend it over the 2nd?
AxterSenior Software Engineer

Commented:
>>You also mention the first is less efficient, so why would you recommend it over the 2nd?

I stated I recommend the typedef on the first one over the 2nd one.
I was not referring to the actual variable declaration and initialization.
AxterSenior Software Engineer

Commented:
>>You also mention the first is less efficient
FYI:
Most compilers will compile away the difference between the two.  But IMHO, why depend on the compiler to do it, when you can setup the code more efficiently yourself.  Moreover the more efficient method requires less code, and IMHO, it's easier to read.

Author

Commented:
gotcha. thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.