if 1=1? WHY?

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 2586 Views - Last Post: 05 June 2013 - 12:45 PM Rate Topic: -----

#16 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: if 1=1? WHY?

Posted 18 May 2013 - 07:10 PM

In C/C++
if(1 = 1)       // this is TRUE
{
  //...do some more code  <---- so this is the only line executed
}
else if(1 = 2)


Was This Post Helpful? 0
  • +
  • -

#17 mb2000inc  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 333
  • Joined: 10-November 09

Re: if 1=1? WHY?

Posted 18 May 2013 - 07:14 PM

View Postpbl, on 18 May 2013 - 10:10 PM, said:

In C/C++
if(1 = 1)       // this is TRUE
{
  //...do some more code  <---- so this is the only line executed
}
else if(1 = 2)



Something like that...
Was This Post Helpful? 0
  • +
  • -

#18 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7292
  • View blog
  • Posts: 12,100
  • Joined: 19-March 11

Re: if 1=1? WHY?

Posted 18 May 2013 - 07:19 PM

Except C should be objecting to assignment to a constant, shouldn't it? This shouldn't compile in C...
Was This Post Helpful? 0
  • +
  • -

#19 mb2000inc  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 333
  • Joined: 10-November 09

Re: if 1=1? WHY?

Posted 18 May 2013 - 07:57 PM

Technically this is C#.
Was This Post Helpful? 0
  • +
  • -

#20 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7292
  • View blog
  • Posts: 12,100
  • Joined: 19-March 11

Re: if 1=1? WHY?

Posted 18 May 2013 - 08:35 PM

Ah. So, not C or C++ at all, then...
Was This Post Helpful? 0
  • +
  • -

#21 BlueMelon  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 187
  • Joined: 27-April 10

Re: if 1=1? WHY?

Posted 19 May 2013 - 04:21 PM

Idk but most languages use == or === to compare and = or := (or similar) to assign...
That's an odd piece of code you have there...
Was This Post Helpful? 1
  • +
  • -

#22 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: if 1=1? WHY?

Posted 19 May 2013 - 05:01 PM

vb uses = for both since in terms of the language grammar its meaning can be contextually inferred.

AreEqual = Part1 = Part2

Red one is assignment
Blue one is value equality comparison (typically).

I say typically since = is an over-loadable operator and the object can change it's meaning to what makes sense in context of the object type.

This post has been edited by AdamSpeight2008: 19 May 2013 - 05:03 PM

Was This Post Helpful? 0
  • +
  • -

#23 mb2000inc  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 333
  • Joined: 10-November 09

Re: if 1=1? WHY?

Posted 21 May 2013 - 08:28 AM

You guys totally understand my nightmare in code.
It's just something I thought I'd share. Since, If I had to suffer through it, so should you. :)
Was This Post Helpful? 0
  • +
  • -

#24 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7292
  • View blog
  • Posts: 12,100
  • Joined: 19-March 11

Re: if 1=1? WHY?

Posted 21 May 2013 - 08:31 AM

View Postmb2000inc, on 21 May 2013 - 10:28 AM, said:

You guys totally understand my nightmare in code.
It's just something I thought I'd share. Since, If I had to suffer through it, so should you. :)/>


I understand perfectly:

Quote

Technically this is C#.


...but I do not suffer from this affliction. :P
Was This Post Helpful? 0
  • +
  • -

#25 mb2000inc  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 333
  • Joined: 10-November 09

Re: if 1=1? WHY?

Posted 21 May 2013 - 08:38 AM

Ha! I'm jealous.

"Ain't nobody got time for that!"
Was This Post Helpful? 0
  • +
  • -

#26 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7292
  • View blog
  • Posts: 12,100
  • Joined: 19-March 11

Re: if 1=1? WHY?

Posted 21 May 2013 - 08:46 AM

Could be worse.

Could be PHP.
Was This Post Helpful? 1
  • +
  • -

#27 mb2000inc  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 333
  • Joined: 10-November 09

Re: if 1=1? WHY?

Posted 21 May 2013 - 08:49 AM

HA!
return true;

Was This Post Helpful? 0
  • +
  • -

#28 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: if 1=1? WHY?

Posted 03 June 2013 - 06:37 PM

Wonder which compiler let you do that... it shouldn'y

if(1 = 1)

will check on HP one on VMS tomorrow
Was This Post Helpful? 0
  • +
  • -

#29 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: if 1=1? WHY?

Posted 04 June 2013 - 06:00 AM

As I though. The DECC compiler don't let it pass by

$ TYPE b.C
#include <stdio.h>

int main(int argc, char **args)
{
if(1 = 1)
printf("Hello\n");
}
$ CC b

if(1 = 1)
.......^
%CC-E-NEEDLVALUE, In this statement, "1" is not an lvalue, but occurs in a context that requires one.
at line number 5 in file DISK$DEVELOPERS:[LAROCHELLEP.DEVELOP]B.C;1
$
Was This Post Helpful? 0
  • +
  • -

#30 mb2000inc  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 333
  • Joined: 10-November 09

Re: if 1=1? WHY?

Posted 05 June 2013 - 12:45 PM

This code was LIVE and in Production. nightmare in code.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2