CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: need C++ programming code in visual studio

    Quote Originally Posted by 2kaud View Post
    Now that's what I call real sneaky where l is already defined in outer block!
    It works, but it's very confusing, especially if you end up finding stuff like this in "production code" you're evaluating.
    With classes it can even get worse when a base class defines a member, and a derived class defines another member with the same name, and then you have virtuals all over the place.


    You even got an octal comparison on the first if just for a change which only fails when all the required rows have been output.
    Not many people know octal notation is even part of the C++ language. Then they get into trouble when they prefix numbers with a 0 for some weird reason (to keep tables aligned is a common reason).

    Quite excited about C++14 finally offering binary literals. For a language (C) that is "close to the machine", it's amazing this wasn't in from the start, and that it has taken so long to add it.




    The 0&')' is not the 'bit of code that does nothing' though, since this obviously DOES do something depending on the value of l. :-)
    Last edited by OReubens; February 12th, 2014 at 07:45 AM.

  2. #17
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: need C++ programming code in visual studio

    Quite excited about C++14 finally offering binary literals. For a language (C) that is "close to the machine", it's amazing this wasn't in from the start, and that it has taken so long to add it.
    People who do 'bit twiddling' probably do it in either octal or hex. When I was doing PDP-11 assembler programming many, many moons ago using octal become second nature.

    Code:
    char('#'^((--l>>8)&')'))
    oh you ******* generating the LF from the xor when l goes negative!

    Having a statement of 0 in the first if obviously does nothing and can be removed.

    It works, but it's very confusing, especially if you end up finding stuff like this in "production code" you're evaluating.
    With classes it can even get worse when a base class defines a member, and a derived class defines another member with the same name, and then you have virtuals all over the place.
    What programmer in their right mind produces production code like this? Its one thing doing a bit of this for 'fun' or to confuse 'newbies' but it's totally different doing this sort of thing in production.
    Last edited by 2kaud; February 12th, 2014 at 08:24 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #18
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: need C++ programming code in visual studio

    Quote Originally Posted by 2kaud View Post
    oh you ******* generating the LF from the xor when l goes negative!
    It's the sort of bit-twiddling using-side-effect-as-result type stuff you find in some of the better bits of assembly (preferably with comments).


    Having a statement of 0 in the first if obviously does nothing and can be removed.
    the 0; does nothing, but removing it will fail to compile, so in that respect, your answer is incorrect.

    I'm talking about a bunch of code you can just remove entirely without affecting the runtime results at all.


    What programmer in their right mind produces production code like this? Its one thing doing a bit of this for 'fun' or to confuse 'newbies' but it's totally different doing this sort of thing in production.
    You would be surprised at the stuff I have found in production code... even production code of "big name" company flagship products. ;-)

  4. #19
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: need C++ programming code in visual studio

    It's the sort of bit-twiddling using-side-effect-as-result type stuff you find in some of the better bits of assembly (preferably with comments).
    Yeah - I gave up assembly programming over 25 years ago! c/c++ is so much better!

    the 0; does nothing, but removing it will fail to compile, so in that respect, your answer is incorrect.
    I didn't say remove the ; - just the 0. Removing the 0 and leaving the ; is syntactically correct.

    Code:
    if (++l-013) 0; else goto elsewhere;
    can be replaced with
    Code:
    if (++l-013)
    as the elsewhere label is immediately following the true condition block. The elsewhere: label can then also be removed - but you get rid of the 'gotos' then!
    Last edited by 2kaud; February 13th, 2014 at 08:13 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured