Hi!
I faced with the fact that in development mode (OpenPLC_Editor) the code is compiled in ANSI-C compatibility,
and in the OpenPLC/webserver project – in C++.
Accordingly, data structures in the first case are initialized with zero,
and in the second case there is no initialization.
The file ‘iec_types_all.h’ contains the following type definition:
#define __DECLARE_IEC_TYPE(type)\
typedef IEC_##type type;\
\
typedef struct {\
IEC_##type value;\
IEC_BYTE flags;\
} __IEC_##type##_t;\
\
typedef struct {\
IEC_##type *value;\
IEC_BYTE flags;\
IEC_##type fvalue;\
} __IEC_##type##_p;
The File ‘accessor.h’ contains calls to this macro depending on the ‘flags’ field.
If we do not take into account that the fields of the structure are not initialized to ‘0’,
then we will get SIGSEG – a memory segmentation error.
That's why I have an ‘accessor.h’ begins with lines:
#ifndef __ACCESSOR_H
#define __ACCESSOR_H
// variable definition
#define __IEC_T(type) __IEC_##type##_t
#define __IEC_P(type) __IEC_##type##_p
// variable primitive
#ifdef __cplusplus
#define __DEFINE_IEC_T(type, name) __IEC_T(type) name={};
#define __DEFINE_IEC_P(type, name) __IEC_P(type) name={};
#define __DEFINE_VAR(type, zone, name)\
type zone##__##name = {};\
static type* GLOBAL__##name = &(zone##__##name);
#else
#define __DEFINE_IEC_T(type, name) __IEC_T(type) name;
#define __DEFINE_IEC_P(type, name) __IEC_P(type) name;
#define __DEFINE_VAR(type, zone, name)\
type zone##__##name;\
static type* GLOBAL__##name = &(zone##__##name);
#endif
...
etc.
Please accept the corrected file ‘accessor.h’,
in which I fixed this error and some other inaccuracies.
Remember, well-written code works immediately after launch!
With best wishes,
Peter