New to C++: Decimals to Integers?

This is a discussion on New to C++: Decimals to Integers? within the C++ Programming forums, part of the General Programming Boards category; It is bad style. So ok ....

  1. #16
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    It is bad style. So ok .
    Woop?

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    It's more than bad style. And macros do cause problems, even with experienced programmers. Microsoft added max and min macros to their windows header, and the C++ standards committee added max and min functions to the algorithm header. They cannot co-exist because of the deficiencies of macros.

    http://www.parashift.com/c++-faq-lit...s.html#faq-9.5

  3. #18
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    incredibly the latest VC++ versions are getting standard compliant, so probably those macros will disapear in about 2/3 years

    Quote Originally Posted by prog-bman
    It is bad style. So ok .
    Code:
    float x;
    int i = *(int*)&x;
    this can also be bad stlye.
    It all up to the programmers responsability. There's nothing wrong with well used and identified macros.

  4. #19
    Registered User
    Join Date
    Jun 2005
    Posts
    6,164
    Quote Originally Posted by xErath
    incredibly the latest VC++ versions are getting standard compliant, so probably those macros will disapear in about 2/3 years
    I doubt it in this case. The macros are in a non-standard header.
    Quote Originally Posted by xErath
    Code:
    float x;
    int i = *(int*)&x;
    this can also be bad stlye.
    It also yields unspecified behaviour. While unspecified behaviour is not evil, it does mean the result is compiler dependent. If a style guide is concerned with portability (e.g. achieving the same results regardless of compiler), I suppose it might describe such tricks might be described as bad behaviour.
    Quote Originally Posted by xErath
    It all up to the programmers responsability. There's nothing wrong with well used and identified macros.
    Depends on your viewpoint.

    Macros, if misused, can be extremely dangerous, as they do text substitution that can make innocent looking code do something it doesn't appear to. Unintended misuse is probably the most dangerous: leaving a trap for some other programmer to encounter and get confused by is probably rarely a good idea. If you think about it, the problem that started this thread is an example can be viewed as an example of unintended misuse.

    Technically, there are VERY few things that can be achieved with macros for which C++ does not provide safe alternatives. The only examples where one absolutely can't live without the preprocessor are with #include'ing headers, ability to define include guards and (arguably) macros such as __LINE__ and __FILE__.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 01:24 PM
  3. Integers into array.
    By livestrng in forum C Programming
    Replies: 10
    Last Post: 10-29-2008, 11:35 PM
  4. Need help to show decimals
    By engstudent363 in forum C Programming
    Replies: 4
    Last Post: 02-19-2008, 03:13 PM
  5. Replies: 6
    Last Post: 08-04-2003, 10:57 AM

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