OT: C syntax question
Let us suppose I have a structure: struct CONTINENT { ... } I use this to create an array of pointers to said struct: struct CONTINENT *Asia[10][10]; Now I pass this array to a function: plate_shift(Asia, (int) foo, (float) bar); In the definition of the function, I say: int plate_shift(Cont,f,b) struct CONTINENT *Cont[10][10]; int f; float b; { ... } and the compiler does not complain. If, however, I try to prototype the function as: extern int plate_shift(struct CONTINENT *[][],int,float); with: CFLAGS = -Wall -std=c99 I get: error: array type has incomplete element type Changing to: extern int plate_shift(struct CONTINENT *foo[][],int,float); returns the same error. KR 2ed is not helpful, nor is a quick poke around the web. What am I forgetting? Respectfully, Robert Huff ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: OT: C syntax question
At 08:41 PM 6/29/2009, Robert Huff wrote: Let us suppose I have a structure: struct CONTINENT { ... } I use this to create an array of pointers to said struct: struct CONTINENT *Asia[10][10]; Now I pass this array to a function: plate_shift(Asia, (int) foo, (float) bar); In the definition of the function, I say: int plate_shift(Cont,f,b) struct CONTINENT *Cont[10][10]; int f; float b; { ... } and the compiler does not complain. If, however, I try to prototype the function as: extern int plate_shift(struct CONTINENT *[][],int,float); with: CFLAGS = -Wall -std=c99 I get: error: array type has incomplete element type Changing to: extern int plate_shift(struct CONTINENT *foo[][],int,float); returns the same error. KR 2ed is not helpful, nor is a quick poke around the web. What am I forgetting? Respectfully, Robert Huff I believe since you are declaring the array as having a fixed number of elements, you must declare the function to take it the same way, like this: extern int plate_shift(struct CONTINENT *[10][10],int,float); Without the 10,10 size definition, the plate_shift function would have no idea how big the array of pointers actually is. Brad Mettee PC HotShots, Inc. Baltimore, MD (410) 426-7617 - Let us bring out the *Power* of your PCs. - - Custom Business Software Solutions since 1991 - visit http://www.pchotshots.com for information about our company. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: OT: C syntax question
Hi-- On Jun 29, 2009, at 5:41 PM, Robert Huff wrote: and the compiler does not complain. If, however, I try to prototype the function as: extern int plate_shift(struct CONTINENT *[][],int,float); with: CFLAGS = -Wall -std=c99 I get: error: array type has incomplete element type You need to provide the size for all but the first element; see KRv2 section 5.9 (p 113), or something like: http://home.netcom.com/~tjensen/ptr/ch7x.htm Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: OT: C syntax question
On Mon 29 Jun 2009 at 17:51:37 PDT Brad Mettee wrote: I believe since you are declaring the array as having a fixed number of elements, you must declare the function to take it the same way, like this: extern int plate_shift(struct CONTINENT *[10][10],int,float); Without the 10,10 size definition, the plate_shift function would have no idea how big the array of pointers actually is. Close. If you pass a two-dimensional array as an argument, you must specify at least the number of elements in the minor dimension, so the compiler will know how to compute, for example, the offset of array[3][0] versus array[6][0]. So this works: extern int plate_shift(struct CONTINENT *[][10], int, float); But the following doesn't work, because it doesn't tell the compiler how to compute the offsets: extern int plate_shift(struct CONTINENT *[10][], int, float); Of course, it doesn't hurt to specify the number of elements in both dimensions. But it would be a less general solution, With only the minor dimension specified, plate_shift can take pointers to arrays of 20, 30, 40, 100 or 200 CONTINENT structures. Any multiple of 10 will do. (But then you need to tell plate_shift when it's reached the last set of pointers, or it might run off the end of the array. The usual way to handle this is to use all NULLs in the last row, as a kind of sentinel.) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: OT: C syntax question
On Mon 29 Jun 2009 at 19:12:10 PDT Charlie Kester wrote: Of course, it doesn't hurt to specify the number of elements in both dimensions. But it would be a less general solution, With only the minor dimension specified, plate_shift can take pointers to arrays of 20, 30, 40, 100 or 200 CONTINENT structures. Any Oops. That's not worded correctly. It should be: ... plate_shift can take a pointer to a multidimensional array of 20,30,40, 100 or 200 CONTINENT structures. (Don't you hate it when your mistakes come back to haunt you in your inbox?) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: OT: C syntax question
On Mon 29 Jun 2009 at 19:20:04 PDT Charlie Kester wrote: On Mon 29 Jun 2009 at 19:12:10 PDT Charlie Kester wrote: Of course, it doesn't hurt to specify the number of elements in both dimensions. But it would be a less general solution, With only the minor dimension specified, plate_shift can take pointers to arrays of 20, 30, 40, 100 or 200 CONTINENT structures. Any Oops. That's not worded correctly. It should be: ... plate_shift can take a pointer to a multidimensional array of 20,30,40, 100 or 200 CONTINENT structures. (Don't you hate it when your mistakes come back to haunt you in your inbox?) I should have quit while I was ahead. If this was a programming interview, I just flunked it. :( ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: OT: C syntax question
Hi, On 30 June 2009 am 10:40:01 Charlie Kester wrote: On Mon 29 Jun 2009 at 19:20:04 PDT Charlie Kester wrote: (Don't you hate it when your mistakes come back to haunt you in your inbox?) at least there is nobody seeing your red face on a mailing list. I should have quit while I was ahead. If this was a programming interview, I just flunked it. :( I would never get the idea asking a programmer questions like this at all. Erich ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
OT: C syntax question
Robert Huff writes: Let us suppose I have a structure: Thanks, everyone - you nailed it in one. Robert What a _maroon_! Huff ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: OT: C syntax question
On Mon 29 Jun 2009 at 19:48:04 PDT Erich Dollansky wrote: I would never get the idea asking a programmer questions like this at all. Yeah, nowadays nobody asks C programming questions in an interview. It's all web programming now. Back in the day, however, I was asked (and asked) questions much like this one. I used to have it down cold, but since I retired my brain cells are forgetting a lot of it. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org