Hello everybody,
I have an issue with all XC16 version from 1.20 to 1.25 with the memset instruction + optimization level s in a very typical situation ...
I tried to simplify my code at maximum ...
/*
* File: newmain.c
* Author:
*
* Created on 17 décembre 2015, 00:05
*/
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
_CONFIG1(WDTPS_PS1 & FWPSA_PR32 & WINDIS_OFF & FWDTEN_OFF & ICS_PGx3 & GWRP_OFF & GCP_OFF & JTAGEN_OFF)
_CONFIG2(POSCMOD_HS & I2C1SEL_PRI & IOL1WAY_OFF & OSCIOFNC_ON & FCKSM_CSDCMD & FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV8 & IESO_OFF)
_CONFIG3(WPFP_WPFP0 & SOSCSEL_IO & WUTSEL_LEG & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPENDMEM)
_CONFIG4(DSWDTPS_DSWDTPS3 & DSWDTOSC_LPRC & RTCOSC_SOSC & DSBOREN_OFF & DSWDTEN_OFF)
/*
*
*/
typedef struct
{
unsigned char BeginHour;
unsigned char EndHour;
}tHoraire;
typedef struct
{
unsigned char
KeyAutorisation : 1,
PushAutorisation: 1,
UnlockAutorisation : 1,
OpeningConstraints: 1,
Dummy: 4;
} tBitFieldOptions;
typedef union
{
unsigned char Content [50];
struct {
unsigned long FingerprintID [4];
unsigned short PINCode;
unsigned char Name[20];
tHoraire Days [7];
tBitFieldOptions Options;
unsigned char OpeningTempo;
};
}tConfigUser;
void Function2 ( unsigned char * User )
{
*User = 0;
}
void Function1 ( tConfigUser User )
{
Function2 ( User.Content );
}
void main ()
{
tConfigUser User;
memset ( ( void* )&User, 0xFF, sizeof ( tConfigUser ) );
Function1 ( User );
}
After memset, the content of User is completely random.
If I comment the line "Function1" -> no more issue
If I don't make call to Function2 with User.Content parameter -> no more issue
If I compile this code without optimization -> no more issue
Has somebody an idea ?
Thanks !