Array of pointer to a structure
I have the following wrote quite a few times and I'm getting the same error for all the lines its on, its properly going to be a silly mistake. So thank you for trying to help.
LINE Code:
if(objContain[0].type == 1) Code:
EXPECTED PRIMARY EXPRESSION BEFORE '[' TOKEN Code:
struct objContain{ Code:
struct objContain *objects; |
Quote:
Code:
if(objects[0].type == 1) Quote:
Quote:
|
Cheers, second simple mistake I've done today =/ well its bed time now, so I try again tomorrow lol.
|
Hi instinct46,
What are you actually trying to accomplish? Although the subject of your post is "Array of pointer to a structure", instead, strictly speaking, you've seemingly declared a pointer to a single structure, and are trying to use it like a single pointer to an array of structures. Some compilers, especially older compilers, would potentially let you get away with that to an extent, if that's what you really want. Some newer compilers with better error checking will complain. cdecl is a handy utility of which various implementations are available on the web. You can use it to double check C declaration syntax. Here's the output of cdecl for three different declaration forms: Quote:
Code:
# include <stdlib.h> Quote:
|
Quote:
Quote:
Quote:
I chose to guess instinct46 wrote roughly the intended code and just titled the question poorly. English is a lot less precise than C. |
The purpose of this thread is to help "instinct46" with a problem. Debating about other issues, seems rather off topic.
To that end I hope that the guess made by "johnsfine" as to what "instinct46" meant, was accurate, even though the guesses "johnsfine" made about what I meant, were incorrect. If it's appropriate at all for LQ, and desirable, we can start threads, perhaps in other forums, about: 1) What do people think is typical in C, and is what's typically done in C, really Professional, or has what's typically done in C, been what's given C a reputation for being more error prone that C++ or Java? 2) In what situations have you seen modern C development environments, complain, at build time or run time, errors or warnings, when you try to use pointers to arrays, for example with pointer arithmetic for multi-dimensional arrays, if you haven't specified the dimensions of the array? 3) Can anyone agree on special considerations for using English grammar to describe C data structures? |
Quote:
Kevin Barry |
Well thank you for all off your replies. I'm a kinda new programmer, by new programmer I mean I've programmed since I was 12 but I've taught myself... so as you may of guessed errors and problems appear in my code.
I love the fact that I'm getting different programming, showing different aspects about my code which are correct/incorrect. I like this group, because its not usual that I can get help with twodimensional pointers to pointers of structures... very rare, my dad taught me. If you want to read the program I will post it below. All I'm trying to do is learn OpenGL, and make a very basic engine to load such games, as pong. You must understand this code is not finished, and by not finished I MEAN really far from finish, but comments are welcome greatly. ////////////////////MAIN FILE/////////////////// Code:
#include <stdio.h> OBJECT HEADER Code:
#ifndef _OBJECT_HEADER_H_ Code:
#ifndef _CONTROLS_HEADER_H_ DEFAULT OBJECTS - MADE FOR TESTING Code:
#include <stdio.h> |
Quote:
I welcome all answers, even those that aren't relate to the question, as long as they are relative to the coding. It is nice to know that people, are willing to give their ideas and "understanding standards" to my code. Sorry everyone about my grammer, I am english and I should know better. (I'm not an english teacher. My dad kinda is, so no doubht he will treat me like a child for a while after seeing this lol.) **EDIT** I had woke up seconds before this, and didn't have minutes to recheck it. |
Quote:
I expect a lot of poor English in this forum because English is a second language for many people posting here. No matter how poor their English is, I am acutely aware that it is better than my second language abilities. So I avoid criticizing. But very bad grammar from someone whose first language is English conveys either laziness or direct disrespect (laziness in the way you ask technical questions also implies a certain disrespect). I'm only commenting on it because you called attention to it yourself. I generally prefer ignore disrespect and/or other flaws in the posts and focus on the technical aspects. (Obviously I'm not 100% successful at that). |
Quote:
The title is wrong, because I didn't know where I was going wrong, otherwise I wouldn't of asked for help. Also bringing up my English, because I brought it up, isn't important. I've seen many people, point out that their English, isn't the best.Yet I've never seen someone, in my time insult someone as you just have. And, how about you give me a break. Your grammar is naff in its self! I came here for coding help not English lessons. I've been at work for 16h shifts, and haven't had a day off in 9days.. and will not have a day off in another 16days! I program, because it is a hobby. I've even had to correct myself a few times, because I'm tired. Also last thing, but my english shouldn't be under-attack! my coding should. |
Quote:
|
All times are GMT -5. The time now is 07:56 PM. |