compile issue with wingw gcc

compile issue with wingw gcc versus MS VirtualStudio 2015 basic

Hey,

I have sources with a makefile. I have used cmake to make a MS VirtualStudio project and to make a mingw project and codeblocks mingw project. With MS VirtualStudio the project compiles without any problem. With mingw32-make I have following compilation problem: error: lvalue required as left operand of assignment. I’m starting to learn C++ and can’t figure this out. This are the two lines with the error:

(HANDLE)me->fd=(HANDLE)HFILE_ERROR;
(HANDLE)priv->fd = (HANDLE)HFILE_ERROR;


I have included the functions were the errors appear and marked the lines in bold. Anyone an idea why this compiles in MS VS and not with mingw32-make.

Thanks

serial_windows.c:237:21: error: lvalue required as left operand of assignment

void serial_close(TDevice * dev)
{
INSTANCE_PTR(dev,struct TSerialWindowsPriv *);

if ((HANDLE)me->fd != (HANDLE)HFILE_ERROR)
{
//No Events anymore...
SetCommMask(me->fd, 0);

FlushFileBuffers( me->fd );

// be sure all IO pendings (Status and Read) are finished !!!!!
PurgeComm(me->fd, PURGE_TXABORT |
PURGE_RXABORT |
PURGE_TXCLEAR |
PURGE_RXCLEAR);

CloseHandle(me->osReader.hEvent);

CloseHandle(me->fd);
(HANDLE)me->fd=(HANDLE)HFILE_ERROR;
}

/* device in state offline now */
dev->DeviceState = DS_OFFLINE;
}

serial_windows.c:615:24: error: lvalue required as left operand of assignment

TDevice * serial_create(DWORD dUnit)
{
TDevice * interfaces;
struct TSerialWindowsPriv * priv;
char cDefaultDev[10];
char cMedia[20];
char cConfigPath[50];

/*
** Device-Struktur und private Struktur initialisieren
*/
interfaces = (void*)malloc(sizeof( TDevice ));
priv = (void*)malloc(sizeof( struct TSerialWindowsPriv ));
if (interfaces && priv)
{
/*
** private Struktur initialisieren
*/
memset(interfaces, 0,sizeof(TDevice));
memset(priv,0, sizeof(struct TSerialWindowsPriv));
interfaces->priv = priv;
interfaces->DeviceState = DS_OFFLINE;

(HANDLE)priv->fd = (HANDLE)HFILE_ERROR;
priv->dBytesSendTotal = 0;

/*
** init driver structure (object instance)
*/
interfaces->Open = serial_open;
interfaces->Close = serial_close;
interfaces->Write = serial_write;
interfaces->Read = serial_read;
interfaces->GetMTU = serial_GetMTU;
interfaces->GetSupportedEvents = serial_GetSupportedEvents;
sprintf(interfaces->cName,"COM%ld", dUnit); /* Treibername */

/*
** Read Settings from Repository (Registry)
*/
sprintf(cConfigPath,"%s.Device", interfaces->cName);
strcpy(cDefaultDev,"COM1");

TRepository_GetElementStr(cConfigPath, cDefaultDev, priv->cPort, sizeof(priv->cPort) );
YASDI_DEBUG((VERBOSE_HWL, "Device = '%s'\n",priv->cPort));

/* Baudrate */
sprintf(cConfigPath,"%s.Baudrate", interfaces->cName);
priv->dBaudrate = TRepository_GetElementInt(cConfigPath, 19200 );
YASDI_DEBUG((VERBOSE_HWL, "Baudrate = %ld\n", priv->dBaudrate));

/* Medium (RS232, RS485 or Powerline) */
cMedia[0]=0;
sprintf(cConfigPath,"%s.Media", interfaces->cName);
TRepository_GetElementStr(cConfigPath, "RS232", cMedia, sizeof(cMedia) );

if (strcmpi(cMedia,"RS232")==0)
priv->media = SERMT_RS232;
if (strcmpi(cMedia,"RS485")==0)
priv->media = SERMT_RS485;
if (strcmpi(cMedia,"Powerline")==0)
priv->media = SERMT_POWERLINE;
YASDI_DEBUG((VERBOSE_HWL, "Media = '%s'\n",cMedia));

/*
** register this new device in the higher layer
*/
(*RegisterDevice)( interfaces );

#ifdef DEBUG
lastCreatedDriverID = interfaces->DriverID;
#endif
}

return interfaces;

}
Last edited on
Left of the assignment operator, you cast your type to a handle using the C-style cast operator. After casting, you get an rvalue. And rvalues may not be assigned to (which is quite understandable, since rvalues are actually values like constants and other non-variable values). Mingw detected this and gives you an error (as it should). Apparently the MS Visual C++ compiler doesn't know that casting gives you an rvalue, or it just didn't check the statements.
Topic archived. No new replies allowed.