Jump to content



Photo

C Static Structs


  • Please log in to reply
4 replies to this topic

#1 preston

preston

    Member

  • Members
  • PipPip
  • 22 posts

Posted 16 February 2012 - 7:26 AM

Hi All,

Im trying to solve a problem with C struct.
This is the structure of the struct in header file that is 'included':

struct plantbl {
char max_harmonic[9];
char max_power_of_t;
signed char *arg_tbl;
double *lon_tbl;
double *lat_tbl;
double *rad_tbl;
double distance;
};


To use this struct, the current code is in this format:

static struct plantbl FAR mer404 = {
{ 11, 14, 10, 11, 4, 5, 2, 0, 0,},
6,
merargs,
mertabl,
mertabb,
mertabr,
3.8709830979999998e-01,
};

However the above code produces this error:

/Users/bliss/Documents/iPhone_Programming/My XCode 4.1 Apps/SwissTest/swemptab.c:1091: error: variable 'mer404' has initializer but incomplete type

FAR btw is a Macro defined as:


# ifndef FAR
# define FAR
# endif
# define MALLOC malloc
# define CALLOC calloc
# define FREE free
#else
# ifndef FAR
# define FAR far
# endif
# ifdef __BORLANDC__
# include <alloc.h>
# define MALLOC farmalloc
# define CALLOC farcalloc
# define FREE farfree
# else
# define MALLOC _fmalloc
# define CALLOC _fcalloc
# define FREE _ffree
# endif
#endif


So anyway...I decide to recode the mer404 to something I thought will be equivalent to the intention of the code above but hopefully does not result in a error...
so I changed the code to:


char placeholder[9] = { 11, 14, 10, 11, 4, 5, 2, 0, 0,};

static struct plantbl FAR mer404 = {
placeholder,
6,
merargs,
mertabl,
mertabb,
mertabr,
3.8709830979999998e-01,
};

but I still get the following error:


/Users/bliss/Documents/iPhone_Programming/My XCode 4.1 Apps/SwissTest/swemptab.c:1080: error: variable 'mer404' has initializer but incomplete type


Now I don't understand why this would be happening....I am trying to feed in values to each of the 7 elements/properties of the struct plantabl..........

Can someone enlighten me on what to do to solve this problem please??? Thank you very much.... :)
  • 0

#2 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,964 posts
  • LocationState College, PA (USA)

Posted 17 February 2012 - 10:42 AM

Just to confirm, are you using C or Objective C? The "iPhone Programming" has me wondering.
  • 0

#3 preston

preston

    Member

  • Members
  • PipPip
  • 22 posts

Posted 19 February 2012 - 11:49 PM

Hi Larry,
I am using C Programming Language inside Xcode which I'll be mixing with Objective-C eventually, but the example code above that I am asking about is C Programming Language. Thank you very much.....
  • 0

#4 preston

preston

    Member

  • Members
  • PipPip
  • 22 posts

Posted 20 February 2012 - 12:55 AM

Hi Larry,

I've figured it out.....the source files in the C Library I am using had not included the corresponding header files with the declaration of the structs. I've added them and it now compiles properly.
Thank you for trying to help :)
  • 0

#5 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,964 posts
  • LocationState College, PA (USA)

Posted 20 February 2012 - 10:41 PM

Ah, that makes sense. Kudos for figuring it out and thanks for sharing the solution.
  • 1