Passing a struct as an array and storing - arrays

My phase looks like this :
enum Gait_cycle_states {
HEEL_STRIKE,
FLAT_FOOT,
MID_STANCE,
HEEL_OFF,
TOE_OFF,
MID_SWING
};
My struct looks like this :
struct State {
Gait_cycle_states current_state;
uint8_t next_state; //index of the next state
uint8_t ay_num_criteria;
State_criterion *ay_criteria_for_state;
unsigned int gy_num_criteria;
State_criterion *gy_criteria_for_state;
};
and my function looks like this :
void initialize_FSM(State states_array[]){
//Heel strike----------------------------------------------------------
State heel_strike = {
.current_state = HEEL_STRIKE,
.next_state = 1, //the index of the next state
.ay_num_criteria = 1,
.ay_criteria_for_state = new State_criterion[1],
.gy_num_criteria = 2,
.gy_criteria_for_state = new State_criterion[2]
};
//The features to look for in accel_y and gyro_y, and how old they can be to count (in ms)
heel_strike.ay_criteria_for_state[0] = { NO_FEATURE, 150 };
heel_strike.gy_criteria_for_state[0] = { NEGATIVE_TROUGH, 150 };
heel_strike.gy_criteria_for_state[1] = { BREACHED_HIGH_THRESHOLD, 30 };
//putting the state we just configured into the state array
states_array[0] = heel_strike;
};
It seems Visual studio 2015 is not letting me assign the value to my types using "." or in the fashion, I am doing it.
It is throwing me a bunch or error and warnings like this :
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(123): error C2059: syntax error: '.'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(131): error C2143: syntax error: missing ';' before '}'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C3927: '->': trailing return type is not allowed after a non-function declarator
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C3484: syntax error: expected '->' before the return type
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C3613: missing return type after '->' ('int' assumed)
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C2146: syntax error: missing ';' before identifier 'ay_criteria_for_state'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C2143: syntax error: missing ';' before '{'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): error C2447: '{': missing function header (old-style formal list?)
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C3927: '->': trailing return type is not allowed after a non-function declarator
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C3484: syntax error: expected '->' before the return type
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C3613: missing return type after '->' ('int' assumed)
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C2086: 'int heel_strike': redefinition
1> c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): note: see declaration of 'heel_strike'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C2146: syntax error: missing ';' before identifier 'gy_criteria_for_state'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C2143: syntax error: missing ';' before '{'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(135): error C2447: '{': missing function header (old-style formal list?)
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C3927: '->': trailing return type is not allowed after a non-function declarator
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C3484: syntax error: expected '->' before the return type
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C3613: missing return type after '->' ('int' assumed)
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C2086: 'int heel_strike': redefinition
1> c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(134): note: see declaration of 'heel_strike'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C2146: syntax error: missing ';' before identifier 'gy_criteria_for_state'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C2143: syntax error: missing ';' before '{'
1>c:\users\arunava nag\documents\visual studio 2015\projects\gaitdetector\gaitdetector\gait_detector.cpp(136): error C2447: '{': missing function header (old-style formal list?)
could someone please suggest me what could be done?

State heel_strike = {
HEEL_STRIKE,
1, //the index of the next state
1,
new State_criterion[1],
2,
new State_criterion[2]
};
What you are trying to use is known as "designated initializers". They are a feature of C language (since C99), not part of standard C++. Some compilers support it for C++ as an extension, but MSVC does not.

Related

Why this multiline macro doesn't work?

Doesn't look like it was parced correctly even. But it looks fine to me.
Maybe it doesn't like newlines? Tried without them.
Maybe it must be in UPPER CASE? I honestly have no idea.
Maybe it doesn't like ////comments?
#define fill(where_l, where_r, where_t, where_b, what_l, what_r, what_t, what_b) \
\
////lt \
*p++ = where_l; \
*p++ = where_t; \
*p++ = 0.5f; \
*p++ = 1.0f; \
*p++ = what_l; \
*p++ = what_t; \
\
////rt \
*p++ = where_r; \
*p++ = where_t; \
*p++ = 0.5f; \
*p++ = 1.0f; \
*p++ = what_r; \
*p++ = what_t; \
\
////lb \
*p++ = where_l; \
*p++ = where_b; \
*p++ = 0.5f; \
*p++ = 1.0f; \
*p++ = what_l; \
*p++ = what_b; \
\
////rb \
*p++ = where_r; \
*p++ = where_b; \
*p++ = 0.5f; \
*p++ = 1.0f; \
*p++ = what_r; \
*p++ = what_b; \
Errors:
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(573) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(573) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(573) : error C2086: 'int *p' : redefinition
Deleted comments completely, now errors are:
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(574) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(574) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(574) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(575) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(575) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(575) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(576) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(576) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(576) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(577) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(577) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(577) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(578) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(578) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(578) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(579) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(579) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(579) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(581) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(581) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(581) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(582) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(582) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(582) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(583) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(583) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(583) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(584) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(584) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(584) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(585) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(585) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(585) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(586) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(586) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(586) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(588) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(588) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(588) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(589) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(589) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(589) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(590) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(590) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(590) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(591) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(591) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(591) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(592) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(592) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(592) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(593) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(593) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(593) : error C2086: 'int *p' : redefinition
1> c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(641) : error C2297: '*' : illegal, right operand has type 'float *'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(641) : error C2017: illegal escape sequence
It looks like your post is mostly code, please add some more details.
Here is how I use it:
float* p = (float*)malloc(999);
fill(i_im_x, i_im_x + 512.0f,
i_im_y, i_im_y + 512.0f,
0.0f, 1.0f,
0.0f, 1.0f);
You need to do this:
Replace all ////xx comments by /* xx */
Remove the stray space character after the \ in following line:
*p++ = where_l; \
^ stray space here
This was not obvious because you cannot see that stray space unless you put the cursor there.
Remove the final \ in the very last line of the macro:
*p++ = what_b; \
^ remove this
Working example:
#define fill(where_l, where_r, where_t, where_b, what_l, what_r, what_t, what_b) \
\
/*lt*/ \
*p++ = where_l; \
*p++ = where_t; \
*p++ = 0.5f; \
*p++ = 1.0f; \
*p++ = what_l; \
*p++ = what_t; \
\
/* rt */ \
*p++ = where_r; \
*p++ = where_t; \
*p++ = 0.5f; \
*p++ = 1.0f; \
*p++ = what_r; \
*p++ = what_t; \
\
/*lb*/ \
*p++ = where_l; \
*p++ = where_b; \
*p++ = 0.5f; \
*p++ = 1.0f; \
*p++ = what_l; \
*p++ = what_b; \
\
/*rb*/ \
*p++ = where_r; \
*p++ = where_b; \
*p++ = 0.5f; \
*p++ = 1.0f; \
*p++ = what_r; \
*p++ = what_b;
int main(int argc, char **argv) {
float* p = (float*)malloc(999);
fill(1, 2, 3, 4, 5, 6, 7, 8)
}

where are the syntax errors am getting?

I am making a program to simulate a game show, randomly. The program picks 1 of three doors for the prize to be hidden behind randomly. The computer picks a door to see if it won or not. This is looped over 10000 times to see how many times I win if I change my pick versus not changing it.
I am getting a bunch of syntax
#include <path-spec>
#include <stdio.h>
#include <time.h>
void count(Status result, Door* pLast_pick, Door* pPick, int* pWin_unchanged, int* pWin_changed);
void randomize_door(Door* pJackpot);
void pick_door(Door* pPick);
Status check(Door* pPick, Door* pJackpot);
enum status {WIN=1,LOSE};
enum door { FIRST=1, SECOND, THIRD };
typedef enum door Door;
typedef enum status Status;
int main(int argc, char* argv[]){
int i = 0;
srand(time);
Status result;
Status* pResult = &result ;
Door jackpot, pick, last_pick=NULL;
Door* pJackpot = &jackpot, * pPick=&pick, *pLast_pick;
int win_unchanged = 0, win_changed=0;
int* pWin_unchanged = &win_unchanged, *pWin_changed=&win_changed;
while (i < 10000){
last_pick = NULL;
randomize_door(pJackpot);
pick_door(pPick);
result = check(pPick, pJackpot);
count(result, pLast_pick, pPick, pWin_unchanged, pWin_changed);
i++;
}
printf("Wins when changed choice: %d , wins when choice is unchanged: %d", win_changed, win_unchanged);
return 0;
}
void randomize_door(Door* pJackpot){
*pJackpot = rand() % 3 + 1;
}
void pick_door(Door* pPick){
*pPick = rand() % 3 + 1;
}
Status check(Door* pPick, Door* pJackpot){
if (*pPick == *pJackpot){
return WIN;
}
else{
return LOSE;
}
}
void count(Status result, Door* pLast_pick, Door* pPick, int* pWin_unchanged, int* pWin_changed) {
if (*pLast_pick == *pPick){
if (result == WIN){
*pWin_unchanged++;
}
}
else{
if (result == WIN){
*pWin_changed++;
}
}
*pLast_pick = *pPick;
}
Below are the errors and which lines its happening at. most of them are forgot } or ; which doesn't make any sense in a function header.
1>------ Build started: Project: Program4.1, Configuration: Debug Win32 ------
1> daily4.c
daily4.c(4): error C2146: syntax error : missing ')' before identifier 'result'
daily4.c(4): error C2061: syntax error : identifier 'result'
daily4.c(4): error C2059: syntax error : ';'
daily4.c(4): error C2059: syntax error : ','
daily4.c(4): error C2059: syntax error : ')'
daily4.c(6): error C2143: syntax error : missing ')' before '*'
daily4.c(6): error C2143: syntax error : missing '{' before '*'
daily4.c(6): error C2059: syntax error : ')'
daily4.c(8): error C2143: syntax error : missing ')' before '*'
daily4.c(8): error C2143: syntax error : missing '{' before '*'
daily4.c(8): error C2059: syntax error : ')'
daily4.c(10): error C2061: syntax error : identifier 'check'
daily4.c(10): error C2059: syntax error : ';'
daily4.c(10): error C2143: syntax error : missing ')' before '*'
daily4.c(10): error C2143: syntax error : missing '{' before '*'
daily4.c(10): error C2143: syntax error : missing ';' before '*'
daily4.c(10): error C2059: syntax error : ')'
daily4.c(16): error C2370: 'Door' : redefinition; different storage class
daily4.c(10) : see declaration of 'Door'
daily4.c(21): warning C4013: 'srand' undefined; assuming extern returning int
daily4.c(24): error C2146: syntax error : missing ';' before identifier 'jackpot'
daily4.c(24): error C2065: 'jackpot' : undeclared identifier
daily4.c(24): error C2065: 'pick' : undeclared identifier
daily4.c(24): error C2065: 'last_pick' : undeclared identifier
daily4.c(24): warning C4047: '=' : 'int' differs in levels of indirection from 'void *'
daily4.c(25): error C2297: '*' : illegal, right operand has type 'int *'
daily4.c(25): error C2065: 'jackpot' : undeclared identifier
daily4.c(25): error C2065: 'pick' : undeclared identifier
daily4.c(25): warning C4047: '=' : 'int' differs in levels of indirection from 'int *'
daily4.c(25): error C2065: 'pLast_pick' : undeclared identifier
daily4.c(25): error C2100: illegal indirection
daily4.c(30): error C2065: 'last_pick' : undeclared identifier
daily4.c(30): warning C4047: '=' : 'int' differs in levels of indirection from 'void *'
daily4.c(31): warning C4013: 'randomize_door' undefined; assuming extern returning int
daily4.c(32): warning C4013: 'pick_door' undefined; assuming extern returning int
daily4.c(33): warning C4013: 'check' undefined; assuming extern returning int
daily4.c(34): warning C4013: 'count' undefined; assuming extern returning int
daily4.c(34): error C2065: 'pLast_pick' : undeclared identifier
daily4.c(43): error C2143: syntax error : missing ')' before '*'
daily4.c(43): error C2143: syntax error : missing '{' before '*'
daily4.c(43): error C2059: syntax error : ')'
daily4.c(43): error C2054: expected '(' to follow 'pJackpot'
daily4.c(48): error C2143: syntax error : missing ')' before '*'
daily4.c(48): error C2143: syntax error : missing '{' before '*'
daily4.c(48): error C2059: syntax error : ')'
daily4.c(48): error C2054: expected '(' to follow 'pPick'
daily4.c(53): error C2143: syntax error : missing ')' before '*'
daily4.c(53): error C2143: syntax error : missing '{' before '*'
daily4.c(53): error C2143: syntax error : missing ';' before '*'
daily4.c(53): error C2059: syntax error : ')'
daily4.c(53): error C2054: expected '(' to follow 'pJackpot'
daily4.c(62): error C2143: syntax error : missing ')' before '*'
daily4.c(62): error C2081: 'Door' : name in formal parameter list illegal
daily4.c(62): error C2143: syntax error : missing '{' before '*'
daily4.c(62): error C2143: syntax error : missing ';' before '*'
daily4.c(62): error C2059: syntax error : 'type'
daily4.c(62): error C2059: syntax error : ')'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
sample to fix
#include <stdio.h>
#include <time.h>
#include <stdlib.h> //for srand
//enum and typedef defined prior to use
enum status {WIN=1,LOSE};
enum door { NONE, FIRST=1, SECOND, THIRD };//Define NONE instead of NULL
typedef enum door Door;
typedef enum status Status;
void count(Status result, Door* pLast_pick, Door* pPick, int* pWin_unchanged, int* pWin_changed);
void randomize_door(Door* pJackpot);
void pick_door(Door* pPick);
Status check(Door* pPick, Door* pJackpot);
int main(int argc, char* argv[]){
int i = 0;
Status result;
Status* pResult = &result ;
Door jackpot, pick, last_pick=NONE;
Door* pJackpot = &jackpot, * pPick=&pick, *pLast_pick;
int win_unchanged = 0, win_changed=0;
int* pWin_unchanged = &win_unchanged, *pWin_changed=&win_changed;
srand(time(NULL));//If you use the equivalent of the C89 compiler can not be mixed the declaration statement and execution statements.
...

Compiling C code in Visual Studio 2013 with complex.h library

http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx
C99 support added visual studio 2013, but I cant use complex.h in my "C" code.
#include <stdio.h>
#include <complex.h>
int main(void)
{
double complex dc1 = 3 + 2 * I;
double complex dc2 = 4 + 5 * I;
double complex result;
result = dc1 + dc2;
printf(" ??? \n", result);
return 0;
}
I get syntax errors.
Edit: Sorry for the missing part.
error C2146: syntax error : missing ';' before identifier 'dc1'
error C2065: 'dc1' : undeclared identifier
error C2088: '*' : illegal for struct
error C2086: 'double complex' : redefinition
error C2146: syntax error : missing ';' before identifier 'dc2'
error C2065: 'dc2' : undeclared identifier
error C2088: '*' : illegal for struct
error C2086: 'double complex' : redefinition
error C2146: syntax error : missing ';' before identifier 'result'
error C2065: 'result' : undeclared identifier
error C2065: 'result' : undeclared identifier
error C2065: 'dc1' : undeclared identifier
error C2065: 'dc2' : undeclared identifier
error C2065: 'result' : undeclared identifier
IntelliSense: expected a ';'
IntelliSense: expected a ';'
IntelliSense: expected a ';'
IntelliSense: identifier "result" is undefined
IntelliSense: identifier "dc1" is undefined
IntelliSense: identifier "dc2" is undefined
In case anyone is searching a year later, try
_Dcomplex dc1 = {3.0, 2.0};
for the variable declaration.
From looking inside VS2013's "complex.h" header, it seems that Microsoft decided on their own implementation for C complex numbers. You'll have to implement your own arithmetical operators using the real() and imag() functions, i.e.:
double real_part = real(dc1) + real(dc2);
double imag_part = imag(dc1) + imag(dc2);
_Dcomplex result = {real_part, imag_part};
Another way is to define like:
/*_Fcomplex */ _C_float_complex a = _FCbuild(5.0F, 1.0F);
printf( "z = %.1f% + .1fi\n", crealf(a), cimagf(a));
/*_Dcomplex*/ _C_double_complex b = _Cbuild(3.0, 2.0);
printf("z = %.1f% + .1fi\n",creal(b), cimag(b));

C - weird syntax error

I'm writing an application in ANSI C (Visual Studio 2010)
my library looks like this:
#include <stdio.h>
#include <stdlib.h>
#ifndef _MYLIB_
#define _MYLIB_
typedef enum {false, true} bool;
// some structures and function prototypes...
#endif
I include this library in every .c file (I've got like 4 .c files - 1 main.c with main() and the rest with functions).
I get an error:
Generating Code...
1> first.cpp
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2059: syntax error : 'constant'
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2143: syntax error : missing ';' before '}'
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2059: syntax error : '}'
1> second.cpp
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2059: syntax error : 'constant'
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2143: syntax error : missing ';' before '}'
1>c:\users\A1\documents\visual studio 2010\projects\pr1\pr1\mylib.h(7): error C2059: syntax error : '}'
What's more - when I paste all functions and structures into main.c - it works properly...
I have no idea how to fix it...
I strongly believe that you are interfering with the C++ built-in false and true, so you are trying to redefine them in your enum.
Try to replace false and true with FALSE and TRUE and bool with BOOL.
#include <stdio.h>
#include <stdlib.h>
#ifndef _MYLIB_
#define _MYLIB_
typedef enum {FALSE, TRUE} BOOL;
// some structures and function prototypes...
#endif

How to Eradicate this error in C Program?

This code is working fine in c++.I need the solution for C.
This is my sample.
FileName:Mail.c
This is the declaration I made in the file mail.c
#ifdef __cplusplus
typedef int (__cdecl *SetIpAddressFun)(char* , int , int );
typedef bool (__cdecl *SendMailFun)(char * , char *);
#endif
I used this function pointers in the function called func() in the same file mail.c
void func()
{
SendMailFun sendMailFuncPtr;
SetIpAddressFun setIpAddressFuncPtr;
}
EDIT
If i remove the #ifdef lines in the file mail.c then it is showing the following error.
error C2143: syntax error : missing ')' before '__cdecl'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(138) : error C2143: syntax error : missing '{' before '__cdecl'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(138) : error C2059: syntax error : ')'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(138) : error C2165: 'left-side modifier' : cannot modify pointers to data
ERROR
List of errors happened while compiling in c.
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1615) : error C2065: 'SendMailFun' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1615) : error C2146: syntax error : missing ';' before identifier 'sendMailFuncPtr'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1615) : error C2065: 'sendMailFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1616) : error C2065: 'SetIpAddressFun' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1616) : error C2146: syntax error : missing ';' before identifier 'setIpAddressFuncPtr'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1616) : error C2065: 'setIpAddressFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1625) : error C2065: 'setIpAddressFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1625) : error C2065: 'SetIpAddressFun' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1625) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1626) : error C2065: 'setIpAddressFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1626) : warning C4047: '!=' : 'void *' differs in levels of indirection from 'int'
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1628) : warning C4013: 'setIpAddressFuncPtr' undefined; assuming extern returning int
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1630) : error C2065: 'sendMailFuncPtr' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1630) : error C2065: 'SendMailFun' : undeclared identifier
e:\projects\avg\apps\ezcepanel i.7 - pcpanel from vss\ccode\alarms.c(1630) : error C2146: syntax error : missing ';' before identifier
This is because when you declared the function
#ifdef __cplusplus
typedef int (__cdecl *SetIpAddressFun)(char* , int , int );
typedef bool (__cdecl *SendMailFun)(char * , char *);
#endif
you do it conditionally only for __cplusplus which is typically not defined when compiling C files
EDIT
I think your second problem is to do with the presence of bool which to my knowledge is not C keyword. Considering replacing it with an int
The #ifdef __cplusplus means that bit of code will only be complied when using a C++ compiler.
It's the bit that defines the function pointer type SendMailFun, so the compiler errors are complaining that SendMailFun and SendMailFun don’t exist.
You could start by removing the lines
#ifdef __cplusplus
and
#endif

Resources