Jul 7, 2006 #1 H Help Advanced Member level 2 Joined Feb 15, 2005 Messages 617 Helped 7 Reputation 14 Reaction score 3 Trophy points 1,298 Activity points 7,065 Hi, Q1) Can we define Array? How to define array? Q2) How the Macros work in C? Do you got any sample? eg. Code: #define MYCASE(_item,_id) \ case _id: \ _item##_##_id=_id;\ break switch(x) { MYCASE(widget,23); } How can we make more selection for our #define MYCASE? Is it posible we add another MYCASE(widget,24); Thank You.
Hi, Q1) Can we define Array? How to define array? Q2) How the Macros work in C? Do you got any sample? eg. Code: #define MYCASE(_item,_id) \ case _id: \ _item##_##_id=_id;\ break switch(x) { MYCASE(widget,23); } How can we make more selection for our #define MYCASE? Is it posible we add another MYCASE(widget,24); Thank You.
Jul 7, 2006 #2 Root Junior Member level 1 Joined Aug 29, 2004 Messages 15 Helped 2 Reputation 4 Reaction score 0 Trophy points 1,281 Activity points 94 Q1) Can we define Array? How to define array? Click to expand... Code: int X[10]; // array of 10 integer numbers double array_of_doubles[100]; small int two[10][10]; // array 10*10 elements of "small int" type Q2) How the Macros work in C? Do you got any sample? Click to expand... a) when you use macros name, C-precompiler pastes in this place macros content. You can use in macros some specific operators (such as ## - concatenate two strings) b) simple macros Code: #define MAX_NUM 10 int array[MAX_NUM]; so we get array with 10 elements... Code: #define MYCASE(_item,_id) \ case _id: \ _item##_##_id=_id;\ break switch(x) { MYCASE(widget,23); } it is equal to this code without macros: Code: switch(x) { case 23: widget_23=23; break; } Is it posible we add another MYCASE(widget,24); Click to expand... it is possible...
Q1) Can we define Array? How to define array? Click to expand... Code: int X[10]; // array of 10 integer numbers double array_of_doubles[100]; small int two[10][10]; // array 10*10 elements of "small int" type Q2) How the Macros work in C? Do you got any sample? Click to expand... a) when you use macros name, C-precompiler pastes in this place macros content. You can use in macros some specific operators (such as ## - concatenate two strings) b) simple macros Code: #define MAX_NUM 10 int array[MAX_NUM]; so we get array with 10 elements... Code: #define MYCASE(_item,_id) \ case _id: \ _item##_##_id=_id;\ break switch(x) { MYCASE(widget,23); } it is equal to this code without macros: Code: switch(x) { case 23: widget_23=23; break; } Is it posible we add another MYCASE(widget,24); Click to expand... it is possible...
Jul 7, 2006 #3 H Help Advanced Member level 2 Joined Feb 15, 2005 Messages 617 Helped 7 Reputation 14 Reaction score 3 Trophy points 1,298 Activity points 7,065 Hi, Q1) Can we define the array as.. Code: #define A array[2]={3,5} If can how the thing work? How the A can know the array elements 3 or 5? Thank You
Hi, Q1) Can we define the array as.. Code: #define A array[2]={3,5} If can how the thing work? How the A can know the array elements 3 or 5? Thank You
Jul 7, 2006 #4 O osmansafa Newbie level 6 Joined Jan 10, 2006 Messages 14 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,390 q1- A can not know 3 and 5 we define it but you may leave a blank instead of writing 2 cuz the array contains 2 elements
q1- A can not know 3 and 5 we define it but you may leave a blank instead of writing 2 cuz the array contains 2 elements