Embedded assignments

This is a discussion on Embedded assignments within the C Programming forums, part of the General Programming Boards category; I was advised against using embedded assignments, such as the following: printf("area equals %f", area = length * width); I ...

  1. #1
    Unregistered
    Guest

    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
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    Code:
    //original statement
    printf("area equals %f", area = length * width);
    Try making this adjustment:
    Code:
    printf("area equals %f", length * width);
    Or even this:
    Code:
    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-01-2009, 11:03 PM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21