Re: Good C programming style




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)

.



Relevant Pages

  • Re: Good C programming style
    ... >> Sensei wrote: ... it's some person arranging that their macro can be expanded ... Chris "electric hedgehog" Dollin ... Prev by Date: ...
    (comp.lang.c)
  • Re: Matrix with headers
    ... Sensei wrote: ... is it so difficult just to set the vanilla \bordermatrix to use custom parenthesis? ...
    (comp.text.tex)
  • Re: Good C programming style
    ... >> Sensei wrote: ... it's some person arranging that their macro can be expanded ... One reason to do this is to save the overhead of a function call. ...
    (comp.lang.c)