Thread: Embedded assignments

  1. #1

    Embedded assignments

    I was advised against using embedded assignments, such as the following:

    printf("area equals %f", area = length * width);

    I certainly understand the point of not using such a construction in the many cases where the clarity of the code to the reader might suffer, but personally, in SOME cases, I find it easier to read these types of assignments, much like it's sometimes more clear to write one long sentence, rather than to break up related ideas into two separate sentences. I was wondering whether there were any functional reason OTHER than readability that it would be a bad idea to use embedded assignments. Thanks ahead for your help!

  2. #2
    Join Date
    Aug 2001
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    //original statement
    printf("area equals %f", area = length * width);
    Try making this adjustment:
    printf("area equals %f", length * width);
    Or even this:
    printf("area equals %f", Area());
    float Area(float length, float width)
      return length * width;
    I compile code with:
    Visual Studio.NET beta2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading and writing to an embedded file
    By HLMetroid in forum C# Programming
    Replies: 4
    Last Post: 01-02-2009, 12:03 AM
  2. Assignments or challenges
    By Dogmasur in forum C Programming
    Replies: 12
    Last Post: 08-20-2008, 02:24 AM
  3. Replies: 3
    Last Post: 04-06-2007, 05:10 PM
  4. embedded c++
    By fizz_uk83 in forum C++ Programming
    Replies: 4
    Last Post: 08-13-2003, 08:09 AM
  5. C++ programming assignments and tests
    By NeoNite in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2003, 05:41 AM