-
Passing enumerate type paramenters in and out of function
Hi All,
I just start learning to program in C for awhile.
I have read several C programming books and websites(also look at their source code) but so far I haven't seen people(even C experts) using
a pointer which points to a enummate
type for function parameters. They are often using pointer to int, float or char as function parameters.
Could anyone explain why in C people try to avoid
(or eliminate)to passing a pointer of enumerate type in and out of function?
If my a function requires to pass in and out more than one parameters of enumerate type
what should I do?
For example code segment below:
/*========Data structures===========*/
typedef enum {ON, OFF) Switch;
typedef enum {LOW, HI, NEUTRAL} Speed;
typedef enum {RUN, STOP, STANBY} Mode;
/*============================================*
* An example of passsing enumType parameters in * and out of function
*==============================================*/
Switch FUN(Speed *Speed_Ptr, /*in and out*/
Mode *Mode_Ptr, /*in and out*/
int RangeLimit /*in*/
)
{
...do some processing/computing here
and send data back to function calls
by return value and pointers.
...
}
Is this valid and good code practice in C???
Especially to mission critical code development.
I really appreciate for your help.
Thanx!
-
and the hat of int overfl
> Is this valid and good code practice in C?
Yes - looks very nice to me
> Could anyone explain why in C people try to avoid
I imagine most tutorials miss out on this step, since when you've got the hang of pointers (say by example, pointer to int), and enumerations in general, explaining pointer to enum is just labouring the point.
There are usually more complicated pointers to get to grips with, like pointers to arrays and pointers to functions.
> what should I do?
Do what you've done
Popular pages
Recent additions