Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

help on typedefs - basic c/c++

Tags:

c++

c

i have been going through some code and came across a statement that somehow disturbed me.

typedef GLfloat vec2_t[2];   

typedef GLfloat vec3_t[3];

From my perspective, a statement such as

typedef unsigned long ulong;

Means that ulong is taken to mean unsigned long
Now, can the statement below mean that vec2_t[2] is equivalent to GLfloat??

typedef GLfloat vec2_t[2];    

Most likely, Probably its not the intended meaning. I would appreciate it if someone clears this up for me. Thanks

like image 377
Dr Deo Avatar asked Nov 30 '22 11:11

Dr Deo


1 Answers

Basically a typedef has exactly the same format as a normal C declaration, but it introduces another name for the type instead of a variable of that type.

In your example, without the typedef, vec2_t would be an array of two GLfloats. With the typedef it means the vec2_t is a new name for the type "array of two GLfloats".

typedef GLfloat vec2_t[2];

This means that these two declarations are equivalent:

vec2_t x;

GLfloat x[2];
like image 130
CB Bailey Avatar answered Dec 05 '22 05:12

CB Bailey