Hi All
consider the following initialization of a struct:
Code:
#include <stddef.h>
#include <stdlib.h>
#include <regex.h>
#include <stdio.h>
#include <string.h>
struct CONFIG
{
int *nos ;
char *data_dir ;
int *ratio ;
regex_t *regex_int ;
regex_t *regex_float ;
} *_myconfig ;
int main(void) {
_myconfig = (struct CONFIG*)malloc(sizeof(_myconfig)) ;
_myconfig->regex_int = calloc(1, sizeof(regex_t)) ;
_myconfig->regex_float = calloc(1, sizeof(regex_t)) ;
regcomp( _myconfig->regex_int, "[[:digit:]]+$", REG_EXTENDED | REG_NOSUB ) ;
regcomp( _myconfig->regex_float, "^[[:digit:]]+\\.[[:digit:]]+$", REG_EXTENDED | REG_NOSUB ) ;
printf("so far so good?") ;
return 0;
}
If you run this code you'll get an Segmentation fault. However when I change the order of fields in the struct like
Code:
struct CONFIG
{
int *nos ;
char *data_dir ;
regex_t *regex_int ;
regex_t *regex_float ;
int *ratio ;
} *_myconfig ;
Any suggestions whats happening here ?
cheers
LuCa