B
Boon
Hello everyone,
I'm trying to use a closed-source library which requires me to define the
following function.
INT InitSem(t_Sem *pSem, UINT32 uiValue);
where
typedef int INT ;
typedef unsigned long UINT32 ;
(I'm not sure what these typedefs buys the library authors, nor what happens
when unsigned long is wider than 32 bits.)
and
typedef unsigned long DWORD ;
typedef DWORD t_Sem[SEM_SIZE_IN_DWORD];
I'm supposed to "tell" the library how big a t_Sem object is by providing an
appropriate definition for SEM_SIZE_IN_DWORD.
However, the actual object is not an array of DWORDs but a struct :
struct REAL_SEM
{
stuff in there;
}
but the library does not want to know the details of the real object, and so it
treats it as an array of SEM_SIZE_IN_DWORD DWORDs.
This means I have to write InitSem like this :
INT InitSem(t_Sem *pSem, UINT32 uiValue)
{
struct REAL_SEM *p = (struct REAL_SEM *)pSem;
/* use p */
return 0;
}
I'm not sure it is "safe" to cast a "pointer to DWORD array" into a "pointer to
struct" is it? What could possibly go wrong?
Regards.
I'm trying to use a closed-source library which requires me to define the
following function.
INT InitSem(t_Sem *pSem, UINT32 uiValue);
where
typedef int INT ;
typedef unsigned long UINT32 ;
(I'm not sure what these typedefs buys the library authors, nor what happens
when unsigned long is wider than 32 bits.)
and
typedef unsigned long DWORD ;
typedef DWORD t_Sem[SEM_SIZE_IN_DWORD];
I'm supposed to "tell" the library how big a t_Sem object is by providing an
appropriate definition for SEM_SIZE_IN_DWORD.
However, the actual object is not an array of DWORDs but a struct :
struct REAL_SEM
{
stuff in there;
}
but the library does not want to know the details of the real object, and so it
treats it as an array of SEM_SIZE_IN_DWORD DWORDs.
This means I have to write InitSem like this :
INT InitSem(t_Sem *pSem, UINT32 uiValue)
{
struct REAL_SEM *p = (struct REAL_SEM *)pSem;
/* use p */
return 0;
}
I'm not sure it is "safe" to cast a "pointer to DWORD array" into a "pointer to
struct" is it? What could possibly go wrong?
Regards.