Thread: NOP in 'C'?

  1. #16
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Oh darn, I should have double-checked all examples given earlier.

    I think that those of us who are happier to apply the rules and remove the empty if branch are more comfortable with changing our thinking about our problem.
    Some people are happier when the way they solve a problem matches their thinking about the problem, but you typically get more optimal code if you change your thinking to fit the problem, as the problem unravels itself in the form of code.
    If fact, sometimes when you change your thinking to fit the problem it comes around full circle. You simplify something much furthur, and as a result and come to see it in a new light and realise that you were seeing the problem wrong.
    Well those are my experiences at least.

    Just don't be afraid to remove the empty if-branch. It's not as difficult to get used to as you might think.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by King Mir View Post
    @matsp & Elysia

    You don't seem to be applying Demorgan's correctly:
    !( (A == 1) && (B == 2) )

    is the same as

    A!=1 || B!=2
    Ehh, you're right. Simple mistake. My mistake >_<
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    DeMorgans:

    The negation of a conjunction is the disjunction of the negations.
    The negation of a disjunction is the conjunction of the negations.

    I don't see how it's confusing...

    If you are not an A or a B:

    Code:
    !(A || B)
    Then you're not an A, and you're not a B:

    Code:
    !A && !B
    Think of it as distributing the negation -- it distributes to the predicates as well as the logical combinators (where the "negation" of OR is AND, and vice versa)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    On a side note, this is why I always use straight-forward expressions such as
    !A && !B
    instead of
    !(A || B)
    Less room to make mistakes.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dll to encrypt packet sends
    By splintter in forum C++ Programming
    Replies: 22
    Last Post: 04-20-2008, 09:00 PM
  2. Which one is "quicker" ?
    By AloneInTheDark in forum C# Programming
    Replies: 2
    Last Post: 02-08-2008, 09:23 PM
  3. nop - revisited
    By oioi in forum Tech Board
    Replies: 4
    Last Post: 12-28-2004, 10:18 AM
  4. Is there anything wrong with my LCD code?
    By ooicheesan in forum C++ Programming
    Replies: 1
    Last Post: 10-18-2004, 01:13 AM
  5. nop
    By Eibro in forum Tech Board
    Replies: 3
    Last Post: 09-02-2002, 08:07 PM