Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

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?
0
PMH4514
Asked:
PMH4514
  • 3
  • 2
1 Solution
 
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
 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now