Re[3]: Срочно! Корректно ли в C преобр-е из void*
|
От: |
SL57
|
|
| Дата: | 04.12.02 08:15 |
|
Оценка: |
|
Здравствуйте, Павел Кузнецов, Вы писали:
ПК>Хуже того — это не является кодом на C.
Я немного потропился.
На С это могдо бы быть так :
///////////////////////////////////////////
// TestServer.h file
///////////////////////////////////////////
enum ETYPE
{
eInt,
eLong
} ;
typedef struct HideType
#ifdef DISABLE_ACCESS
{
void* mData;
enum ETYPE mType;
}
#endif
HideType;
void CreateMyVariant(HideType** aRetVal);
void SetInt(const HideType* aParam,int aVal);
void SetLong(const HideType* aParam,long aVal);
int GetInt(const HideType* aParam);
long GetLong(const HideType* aParam);
///////////////////////////////////////////
// TestServer.c file
///////////////////////////////////////////
#define DISABLE_ACCESS
#include "TestServer.h"
#undef DISABLE_ACCESS
void CreateMyVariant(HideType** aRetVal)
{
// ...
}
void SetInt(const HideType* aParam,int aVal)
{
// ...
}
void SetLong(const HideType* aParam,long aVal)
{
// ...
}
int GetInt(const HideType* aParam)
{
if(aParam && eInt == aParam->mType)
return *((int*)(aParam->mData));
return 0;
}
long GetLong(const HideType* aParam)
{
if(aParam && eLong == aParam->mType)
return *((long*)(aParam->mData));
return 0;
}
///////////////////////////////////////////
// TestClient.c file
///////////////////////////////////////////
#include "TestServer.h"
HideType* theType = 0;
CreateMyVariant(&theType);
SetInt(theType,10);
// ...
Пока на собственное сообщение не было ответов, его можно удалить.