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

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?
PMH4514Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AxterCommented:
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).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PMH4514Author 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?
0
AxterCommented:
>>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.
0
AxterCommented:
>>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.
0
PMH4514Author Commented:
gotcha. thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.