C array dimension problem -


i have array 1653 lines this:

#define num_polygon_object_vertex 1653 * 3  static const float vertices[num_polygon_object_vertex] = {    {{2.4f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f} },    ... }; 

which right value num_polygon_object_vertex?

thanks

update

don't have idea programming c , paid me -3 points. unbelievable

second update i'm getting following error:

warning: excess elements in scalar initializer 

at least imo, right thing leave num_polygon_object_vertex out entirely:

static const float vertices[] = {    {{2.4f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f} },    ... }; 

the compiler compute size automatically based on initialization data. compute size afterward, can use like:

#define elements(array) (sizeof(array)/sizeof(array[0])) 

note, however, have doesn't seem multi-dimensional array @ (nor c's closest equivalent, array of arrays). since have 1 set of brackets, have single-dimension array. if want create multi-dimension array, like:

static const float vertices[][3] = {    {{2.4f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f} },    ... }; 

note added [3] -- tells compiler want array of arrays of 3 floats apiece. mean vertices[0] entire array of 3 floats make first vertex, , vertices[0][1] (at least conventionally) x value of first vertex.

if define array way, can still use elements macro above -- since vertices[0] complete vertex instead of single float, number of elements number of vertices instead of number of floats.

based on braces you've included, may want be:

static const float lines[][2][3] = { /* ... */ }; 

right bracing says have pairs of vertices, , pair of vertices defines line...


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -