Originally Posted by
rk211083
I'm facing a segmentation fault(core) at the step where a structure variable is declared.
PFB the code snippet:
insert
Code:
struct LOCAL_UTILS_struct_
{
tbaAmtType bigLimitAmt;
longDescType longDesc;
tba800ErrorMsgType mlStr01;
};
typedef struct LOCAL_UTILS_struct_ LOCAL_UTILS_STRUCT_TYPE;
Function ()
{
LOCAL_UTILS_STRUCT_TYPE locUtils;
Above line is giving segmentation fault; but not always. When structure eliminated, and structure variables declared separately inside function, core didn’t occur.
Also, I declared a dummy string above this structure declaration of size 30000. Then the core didn’t occur.
Please suggest probable reason for this behaviour.
You have not provided a type, just a definition, the correct declaration is:
Code:
struct
{
tbaAmtType bigLimitAmt;
longDescType longDesc;
tba800ErrorMsgType mlStr01;
}LOCAL_UTILS_struct_;
If you want to typedef it, and make at tag and pointer type at the same time, the statement is:
Code:
typedef struct LOCAL_UTILS_struct_tag
{
tbaAmtType bigLimitAmt;
longDescType longDesc;
tba800ErrorMsgType mlStr01;
}LOCAL_UTILS_struct_t, *pLOCAL_UTILS_struct_t;
The tag can be used to declare this type of struct inside the struct, the type is the LOCAL_UTILS_struct_t (the _t is just my decoration of typedef types), and the pointer type is pLOCAL_UTILS_struct_t (here both the p and _t are my decoration).