Re: Good C programming style
- From: "Gregory Pietsch" <GKP1@xxxxxxxxx>
- Date: 7 Oct 2005 14:58:43 -0700
Sensei wrote:
> Hi!
>
> I'm thinking about a good programming style, pros and cons of some
> topics. Of course, this has nothing to do with indentation... Students
> are now java-dependent (too bad) and I need some serious motivations
> for many issues... I hope you can help me :) I begin with the two major
> for now, others will come for sure!
>
> - function variables: they're used to java, so no pointers. Personally
> I'd use always pointers, but why could be better to use:
> void myfun(int &i) or (int *i) or (int i)
int &i is not standard C.
> given that the function can and cannot (the last case of course) modify
> a parameter. I see performance issues (stack related)...
>
> - defines: why they use function and variable defines? why they shouldn't?
> #define MY_PI 3.1415
You might want to extend pi a few more decimal places. The SUSv3
standard has a macro M_PI in <math.h>, but it isn't ISO-99 C.
> #define fun(x) ((x) * (x))
This is considered bad style for a macro because the macro argument is
evaluated twice. Imagine what would happen if the argument to the macro
contained an increment or decrement operator.
Gregory Pietsch
>
>
> --
> Sensei <senseiwa@xxxxxxx>
>
> The difference between stupidity and genius is that genius has its
> limits. (A. Einstein)
.
- Follow-Ups:
- Re: Good C programming style
- From: Richard Heathfield
- Re: Good C programming style
- References:
- Good C programming style
- From: Sensei
- Good C programming style
- Prev by Date: Re: Good C programming style
- Next by Date: Re: Dynamic Array
- Previous by thread: Re: Good C programming style
- Next by thread: Re: Good C programming style
- Index(es):
Relevant Pages
|