#pragma to switch off compiler optimization

Hi,is there any possibilty to switch off/on compiler code optimization by #pragma inside code?

You can do a #pragma pack(1) in front of the structure and #pragma pack()at the end. The whole thing then looks like this: #pragma pack(1) typedef struct serial_port { PORT_NUMBER portNumber; BAUD_RATE baudRate; DATA_BIT dataBit; PARITY parity; STOP_BIT stopBit; FLOW_CONTROL flowControl; HAND_SHAKE handShake; PROTOCOL protocol; CU_UINT8 reserved[10]; // future use } SERIAL_PORT; #pragma pack() However, please be aware that this may cause problems in case long variables are placed on addresses which are not dividable by 4 or short variables which are placed on addresses not dividable by 2, i.e. these values are unaligned in memory. Our memory controller does not support that. In case you try to read a long value from address 2, the value read will contain bytes 0, 1, 2, 3 and not 2, 3, 4, 5 since address bits 0 and 1 are ignored during long word accesses. To overcome this issue you may apply the compiler switch -X1719. A long word access to an unaligned address will then be spitted to two half word accesses or four byte accesses, which basically makes things less performant. I would prefer not to work with packed structures and live with the higher memory requirements.

Thanks for your response, but that doesn’t help me very much. I have a problem with a source code file. Turning on compiler optimization (speed optimization tab) for this file, the compiler stucks (windows 2000 popup message: ccomarm.exe … read at address … not successful). I found the routine causing this problem (see below), but I couldn’t find the reason. My idea is, to switch off code optimization for this routine by #pragma. Routine (DLL_as_IdTab[w_cnt].bptr-=dlen+2; within for loop cuases the problem): UINT8 DLL_DeleteCOB( UINT16 cobhdl ) { UINT8 dlen; UINT16 w_cnt; UINT8 pb_UpdBuf; if (cobhdl >= 2048) { return DLL_k_NO; } if(DLL_as_IdTab[cobhdl].config != FALSE) { if(DLL_as_IdTab[cobhdl].bptr != NULL) { pb_UpdBuf=DLL_as_IdTab[cobhdl].bptr; #if(HB_LA) dlen=((UINT8 )(pb_UpdBuf+1)&0x0F); #else dlen=((UINT8 )(pb_UpdBuf)&0x0F); #endif MEMMOVE (pb_UpdBuf, pb_UpdBuf+dlen+2, DLL_pb_UpdBufEnd-pb_UpdBuf+dlen+2); for(w_cnt=cobhdl;w_cnt<2048;w_cnt++) { if(DLL_as_IdTab[w_cnt].config != FALSE && DLL_as_IdTab[w_cnt].bptr!= NULL) { DLL_as_IdTab[w_cnt].bptr-=dlen+2; } } DLL_pb_UpdBufEnd-=dlen+2; } } else return DLL_k_OK; / clear Software filter */ DLL_as_IdTab[cobhdl].config=FALSE; return DLL_k_OK; }