sciwizeh 62 Posting Pro in Training

Hello, I'm not sure that this shouldn't be in the Computer Science Board because it is mostly a theory question, but it is also implemented in C, so here it goes.

I've been looking at some ways to make a modifiable array to hold geometric data for a simplistic 3D program (using OpenGL). Looking through the web, and I found one way to store changeable information something along the lines of:

typedef GLfloat point[3];

int number=5;
point *polygon;
...
void addPoint(point p){
   number ++;
   *(point+number-1)=p;
}

Now that may not be right, I haven't actually tried to implement anything yet, because for some reason this doesn't seem ... safe.

It seems as though this could be bad if other items are in the heap. For example, for simplicities sake lets say that the heap can hold 10 integers. So, a pointer to the first position is like the polygon pointer above, and another is made that is in the fifth position. If number gets to or exceeds 6 then whatever integer was last added replaces what happens to be in the fifth position.

Will this happen? And is there a way to prevent it? And how else can this be accomplished, possibly in a safer way?

A link will suffice, just something on the theory behind this. Something that will help me understand this concept and how it is or isn't hazardous to do.

If I'm not being clear enough please ask for clarification.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.