assignment advantages ???

From: Billy N. Patton (b-patton_at_ti.com)
Date: 09/08/04


Date: Wed, 08 Sep 2004 07:47:12 -0500

In the book I'm reading to lean c++
It has this assignment
int a_sum = 0 , v_sum = 0;

I do it in c as:
int a_sum = v_sum = 0;
OR
int a_sum; // for the summation from the array
int b_sum; // for the summation from the vector
a_sum = 0; // needs to be 0
b_sub = 0; // needs to be 0

Was this just personal preference of the author or is there and
advantage to using comma seperated statements?

I realize that in a program where this is done once, it wouldn't matter.
But if this were in a funcion that is called millions of times then
speed could become a factor.

-- 
    ___  _ ____       ___       __  __
   / _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
  / _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
            /___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com


Relevant Pages

  • Re: assignment advantages ???
    ... |> In the book I'm reading to lean c++ ... | That's not assignment, that's initialisation. ... | int a_sum = 0; ... In any case, you are correct, in that it is initialisation ...
    (alt.comp.lang.learn.c-cpp)
  • Re: assignment advantages ???
    ... | int b_sum; // for the summation from the vector ... Additionally, there is also the disadvantage, that ... is to declare each variable at the ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Implementation of Kahan sum algorithm
    ... No, it minimizes summation roundoff or truncation errors due to unequal scale factors, not conversion errors. ... double kahanSum(double input, double tosum, double times) ... int count; ...
    (comp.lang.c)
  • Re: f(x) = g(x) + g(x+1) ------ f(x) is known, g(x)=?
    ... > I have two clues about g. ... > an Int (or floor) function and a mod operator in it. ... > complicated for me to solve that summation. ...
    (sci.math)
  • Re: why does C standard allow this declaration
    ... "b" is defined at line 4 but the assignment at line 5 is skipped. ... when the control flow of the program "passes through" that statement. ... int silly_func ... The first line inside the brace is a declaration with an initializer, ...
    (comp.lang.c)