[SDL] Question about arrays...

Kuon - Nicolas Goy - 時期精霊 (Goyman.com SA) kuon at goyman.com
Sat Feb 10 05:26:10 PST 2007


On Feb 9, 2007, at 7:59 PM, SlntHero at aol.com wrote:

> Question about arrays...

Just because the discussion started, let me introduce a little tip.

To manage our vector, we have something like this:

typedef struct {
	Float32 *v; /** Float 32, is just a 32 bit float, part of our lib,  
same with Float16, Float64, Float80 and Float96. Note that only  
Float32 and Float64 are standard in C other are proprietary of our  
lib */
	Uint8 d;
} Vector32;

/* Those things are our standard API for pseudo object programming in  
C */
Vector32_alloc(Vector32 **v) {
	*v = malloc(sizeof(Vector32));
}
Vector32_init(Vector32 *v) {
	v->d = 0;
	v->v = NULL;
}
Vector32_setDimension(Vector32 *v, Uint8 d) {
	if(!v || v->v) return;
	v->d = d;
	v->v = malloc(d * sizeof(Float32));
}
/* What is of some interest for you, maybe */
Vector32_setData(Vector32 *v, ...) {
	va_list l;
	va_start(l, v);
	char *p;
	int i;
	for(*p = v, i = 0; *p && i < v->d /* We also verify dimension, if  
too much args are passed */; p++, i++) {
		v->v[i] = va_arg(l, Float32);
	}
	va_end(l);
}

I did not copy past that code, I wrote it on the fly, so do not blame  
me if a little typo inserted itself somewhere. It's just for the  
concept. You can apply the setData function to anything.

Regards
-- 
Kuon
Programmer and sysadmin.

"Computers should not stop working when the users' brain does."





-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2434 bytes
Desc: not available
Url : http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070210/8a6d80d4/attachment.bin 


More information about the SDL mailing list