Searching \ for '[EE] bonehead move of the day' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=bonehead+move+day
Search entire site for: 'bonehead move of the day'.

Exact match. Not showing close matches.
PICList Thread
'[EE] bonehead move of the day'
2009\08\24@133411 by Mark Rages

face picon face
So I found out today that P-channel MOSFET in SOT23 will function in
place of a three-terminal regulator in SOT23.  Except for the
"regulation" part.

The transistor had "33" printed on it, so I assumed it was the 3.3V
LDO.  Wrong assumption.

Looks like the rest of the circuit survived.  I was impressed with how
bright my LEDs were shining.

Regards,
Mark
markrages@gmail
--
Mark Rages, Engineer
Midwest Telecine LLC
spam_OUTmarkragesTakeThisOuTspammidwesttelecine.com

2009\08\24@143929 by M. Adam Davis

face picon face
That's pretty funny!

Replacing a co-worker's regulators with P channel mosfets is a
practical joke on par with putting
#define if while
in one of their rarely used header files.

-Adam

On Mon, Aug 24, 2009 at 1:34 PM, Mark Rages<.....markragesKILLspamspam@spam@gmail.com> wrote:
{Quote hidden}

>

2009\08\24@145051 by Vitaliy

face
flavicon
face
M. Adam Davis wrote:
Replacing a co-worker's regulators with P channel mosfets is a
practical joke on par with putting
#define if while
in one of their rarely used header files.

===

Sorry, what does "#define if while" do?

Vitaliy


PS Any chance you could turn off quoted-printable for your emails to the
PICList? :)

2009\08\24@145959 by peter green

flavicon
face
Vitaliy wrote:
> M. Adam Davis wrote:
> Replacing a co-worker's regulators with P channel mosfets is a
> practical joke on par with putting
> #define if while
> in one of their rarely used header files.
>
> ===
>
> Sorry, what does "#define if while" do?
>  
It makes the C compiler interpret if as while of course. This means that
either the code will fail to compile for no obvious reason or that the
code will misbehave big time.

"#define while if" is even worse because it's less likely to cause
compile errors and more likely to cause code that doesn't behave right.

> Vitaliy
>
>
> PS Any chance you could turn off quoted-printable for your emails to the
> PICList? :)
>
>  

2009\08\24@154213 by Philip Pemberton

face
flavicon
face
peter green wrote:
> Vitaliy wrote:
>> Sorry, what does "#define if while" do?
>>  
> It makes the C compiler interpret if as while of course. This means that
> either the code will fail to compile for no obvious reason or that the
> code will misbehave big time.
>
> "#define while if" is even worse because it's less likely to cause
> compile errors and more likely to cause code that doesn't behave right.

For bonus points, add it to one of the runtime library headers :)

stdio.h, stdlib.h and crew are used in almost every C program. For
MPLAB-C18? Why, you butcher stddef.h, of course. The rest of the RTL (or
most of it at least) pulls this in, thus increasing the evilness :)

For additional bonus points, hide the #define in a bank of function
definitions or other #defines.

Do not, however, expect your workmates/colleagues to be friends with you
after this...

--
Phil.
.....piclistKILLspamspam.....philpem.me.uk
http://www.philpem.me.uk/

2009\08\24@154424 by Philip Pemberton

face
flavicon
face
Mark Rages wrote:
> The transistor had "33" printed on it, so I assumed it was the 3.3V
> LDO.  Wrong assumption.

Thou shalt checketh thy datasheet before soldering!

Second commandment of electronics. Right after "Thou shalt not putteth
thy fingers across a live AC feed."

Also, a P-touch printer (e.g. the ~£20 PT-1010) and 6mm black-on-white
tapes are great for labelling the black plastic tapes that SOT23s (among
other things) are usually shipped in. Put in an 18mm tape and they work
just as well for the little SMD component boxes you can get on
Dealextreme and eBay.

The PC-connectable printers are far nicer though. Mainly because you can
export your components database (if you have one) into a CSV file, tell
the label printing software which fields to print, hit "print" and go
have lunch. Applying the labels isn't much fun, but it beats
hand-labelling with a Sharpie pen...

--
Phil.
EraseMEpiclistspam_OUTspamTakeThisOuTphilpem.me.uk
http://www.philpem.me.uk/

2009\08\24@160048 by Vitaliy

face
flavicon
face
peter green wrote:
>> Sorry, what does "#define if while" do?
>>  
> It makes the C compiler interpret if as while of course. This means that
> either the code will fail to compile for no obvious reason or that the
> code will misbehave big time.
>
> "#define while if" is even worse because it's less likely to cause
> compile errors and more likely to cause code that doesn't behave right.
>

Duh! :(

Don't know why I was overthinking it. Thanks for the explanation.

Vitaliy

2009\08\24@162708 by Wouter van Ooijen

face picon face
>> Sorry, what does "#define if while" do?
>>  
> It makes the C compiler interpret if as while of course. This means that
> either the code will fail to compile for no obvious reason or that the
> code will misbehave big time.

What code would fail to compile (which is of course the most 'fortunate'
of the possible effects!)?

--

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu

2009\08\24@164254 by Mark Rages

face picon face
On Mon, Aug 24, 2009 at 3:26 PM, Wouter van Ooijen<wouterspamspam_OUTvoti.nl> wrote:
>>> Sorry, what does "#define if while" do?
>>>
>> It makes the C compiler interpret if as while of course. This means that
>> either the code will fail to compile for no obvious reason or that the
>> code will misbehave big time.
>
> What code would fail to compile (which is of course the most 'fortunate'
> of the possible effects!)?

Can while {} have an else {} clause?

Regards,
Mark
markrages@gmail
--
Mark Rages, Engineer
Midwest Telecine LLC
@spam@markragesKILLspamspammidwesttelecine.com

2009\08\24@164413 by Marcel Birthelmer

picon face
> What code would fail to compile (which is of course the most 'fortunate'
> of the possible effects!)?

if ( ... )
{
...
}
else
{
...
}

2009\08\24@171646 by Wouter van Ooijen

face picon face
> Can while {} have an else {} clause?

OK! So it should have been

#define while if
#define else

Could that still produce compiler errors?

--

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu

2009\08\24@180129 by Gerhard Fiedler

picon face
Wouter van Ooijen wrote:

>> Can while {} have an else {} clause?
>
> OK! So it should have been
>
> #define while if
> #define else
>
> Could that still produce compiler errors?

You probably meant

#define if while
#define else

With

#define while if

there is no define for the else clause necessary.

I think the latter version is more evil. It causes more subtle errors;
the first one will very likely hang in the first if clause the code
reaches.

Gerhard

2009\08\24@181103 by Marcel Birthelmer

picon face
>
> #define while if
>

This would choke on break/continue statements, though.

2009\08\24@182558 by M. Adam Davis

face picon face
I love how we're sitting around thinking about the most evil way to
utterly break someone's code in a non-obvious fashion.

This is hilarious!

So now we've got either

#define while if
#define continue
#define break

or

#define if while
#define else

The problem with the first is that it would break many more things
than intended, as it would also affect for loops and switch
statements.  I like that the program would continue to run, though -
it wouldn't enter an infinite loop inside an if statement.

The second very narrowly targets if statements, but would be easier to
catch as the program would likely stall inside the first if statement
that evaluates to true.

Either way, someone doing this would likely find a shiv made out of a
co-worker's keyboard in their back.

-Adam

On Mon, Aug 24, 2009 at 6:11 PM, Marcel
Birthelmer<KILLspammarcelb.listsKILLspamspamgmail.com> wrote:
>>
>> #define while if
>>
>
> This would choke on break/continue statements, though.
> -

2009\08\24@183506 by Marcel Birthelmer

picon face
On Mon, Aug 24, 2009 at 3:25 PM, M. Adam Davis<RemoveMEstienmanTakeThisOuTspamgmail.com> wrote:
> I love how we're sitting around thinking about the most evil way to
> utterly break someone's code in a non-obvious fashion.
>
> This is hilarious!
>
> So now we've got either
>
> #define while if
> #define continue
> #define break
>
> or
>
> #define if while
> #define else

How about
#define while(x) while(! (x) )

Or the classic,
#define NULL ((void*)1)

2009\08\24@183707 by Mark Rages

face picon face
On Mon, Aug 24, 2009 at 5:25 PM, M. Adam Davis<spamBeGonestienmanspamBeGonespamgmail.com> wrote:
{Quote hidden}

go for random failure:

#define if(x)  if ((x) & PORTA)

--
Mark Rages, Engineer
Midwest Telecine LLC
TakeThisOuTmarkragesEraseMEspamspam_OUTmidwesttelecine.com

2009\08\24@224140 by solarwind

picon face
On Mon, Aug 24, 2009 at 3:36 PM, Mark Rages<RemoveMEmarkragesspamTakeThisOuTgmail.com> wrote:
> go for random failure:
>
> #define if(x)  if ((x) & PORTA)

LOL! Best one so far!

2009\08\25@091823 by Philip Pemberton

face
flavicon
face
Mark Rages wrote:
> go for random failure:
>
> #define if(x)  if ((x) & PORTA)

Or for even more fun, drive it off of TMR0:

#define if(x) T0CON ^= 0x80; if ((x) & TMR0L)

Or even:
#define if(x) T0CON ^= 0x80; if ((x) & (TMR0L == TMR0H))

Which toggles the timer on-state every time an 'if' statement rolls
around. I'd file this under "absolutely evil" -- if the code makes use
of TMR0 it's going to completely screw up the timing, if it doesn't...
well... good luck figuring out what's going on, especially if TMR0L
wasn't initialised to a defined value on boot (most 18Fs clear TMR0H to
zero on any reset, but it's undefined on wakeup from SLEEP; TMR0L is
undefined at any reset or wakeup).

--
Phil.
piclistEraseMEspam.....philpem.me.uk
http://www.philpem.me.uk/

2009\08\25@095539 by M. Adam Davis

face picon face
I was thinking something along those lines as well, but reduce the
probability of an error so it's less frequent and seemingly more
random:

#define if(x) T0CON |= 0x80; if ((x) & (TMR0L & 0xF))

Would only have a 1 in 16 chance of affecting the if.  It wouldn't
mess up the timer unless they were turning the timer on and off inside
the program (usually it's either on or off for the entire program, if
it's off then they probably arent' using it, and if it's on our
statement doesn't affect that).

Could go downhill from here, but of course the more we change each if
statement, the easier it'll be to see there's a big problem when
someone examines the compiler output.

-Adam

On Tue, Aug 25, 2009 at 9:18 AM, Philip Pemberton<EraseMEpiclistspamphilpem.me.uk> wrote:
{Quote hidden}

>

2009\08\25@115355 by Sean Breheny

face picon face
In MATLAB, you can freely re-define pi and i. Setting pi=2 or 10 can
make for some interesting debugging of code :)

Sean


On Tue, Aug 25, 2009 at 9:55 AM, M. Adam Davis<RemoveMEstienmanspam_OUTspamKILLspamgmail.com> wrote:
{Quote hidden}

>> -

2009\08\25@115534 by Sean Breheny

face picon face
What is a "continue" statement? I assumed we were talking about C
here, I've never seen a C keyword "continue"

Also, I think that break DOES work inside the {} following an IF
statement. It immediately takes you out of the {}.

Sean


On Mon, Aug 24, 2009 at 6:11 PM, Marcel
Birthelmer<RemoveMEmarcelb.listsKILLspamspamgmail.com> wrote:
>>
>> #define while if
>>
>
> This would choke on break/continue statements, though.
> -

2009\08\25@120738 by Wouter van Ooijen

face picon face
Sean Breheny wrote:
> What is a "continue" statement? I assumed we were talking about C
> here, I've never seen a C keyword "continue"

continue terminates the current iteration of a loop and starts the next
iteration. Sort of a legal way to goto to the end (not beyond!) of a loop.

--

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu

2009\08\25@121548 by Carl Denk

flavicon
face
Per my "The C Programmer's Handbook", AT&T Bell labs. 1985:
continue : Goes to top of smallest enclosing "while, do, or for"
statement, causing it to repeat execution. This is the "opposite" of the
break statement.

I learned something too :) :)

Sean Breheny wrote:
{Quote hidden}

>> --

2009\08\26@124522 by Byron Jeff

flavicon
face
On Tue, Aug 25, 2009 at 12:15:40PM -0400, Carl Denk wrote:
> Per my "The C Programmer's Handbook", AT&T Bell labs. 1985:
> continue : Goes to top of smallest enclosing "while, do, or for"
> statement, causing it to repeat execution. This is the "opposite" of the
> break statement.

One further item. On a 'for' statement, the continue will execute the post
loop statement of the 'for' before moving on to the next iteration.

BAJ

{Quote hidden}

2009\08\26@125120 by Byron Jeff

flavicon
face
On Tue, Aug 25, 2009 at 11:55:32AM -0400, Sean Breheny wrote:
> What is a "continue" statement? I assumed we were talking about C
> here, I've never seen a C keyword "continue"

Answered elsewhere.

>
> Also, I think that break DOES work inside the {} following an IF
> statement. It immediately takes you out of the {}.

Nope. 2 second test

Code:

#include <stdio.h>

main()
{
  int a = 1;

  if (a == 1) {
     printf("Before break\n");
     break;
     printf("After break\n");
  }
  else {
     printf("before break in else\n");
     break;
     printf("before break in else\n");
  }
}

Produced.

cc     testme.c   -o testme
testme.c: In function 'main':
testme.c:9: error: break statement not within a loop or switch
testme.c:14: error: break statement not within a loop or switch
make: *** [testme] Error 1

Continues and breaks only work within certain constructs.

BAJ
{Quote hidden}

2009\08\26@131023 by Sean Breheny

face picon face
Thanks for the information on "continue" and I stand corrected on "break".

Sean


On Wed, Aug 26, 2009 at 12:51 PM, Byron Jeff<EraseMEbyronjeffspamEraseMEclayton.edu> wrote:
{Quote hidden}

2009\08\26@132653 by John Coppens

flavicon
face
On Wed, 26 Aug 2009 12:51:34 -0400
Byron Jeff <spamBeGonebyronjeffspamKILLspamclayton.edu> wrote:

> Continues and breaks only work within certain constructs.

Ok... The break would have taken you out of a for, if the if statement
were inside a for:

for (i = 0; i < 3; i++) {
  if (a == 1) {
     printf("Before break\n");
     break;
     printf("After break\n");
  }
  else {
     printf("before break in else\n");
     break;
     printf("before break in else\n");
  }
}

compiles ok and produces:

Before break

This is, of course, not an example of elegant programming, but could
explain why the 'break' worked.

John

2009\08\27@115119 by Gerhard Fiedler

picon face
John Coppens wrote:

> On Wed, 26 Aug 2009 12:51:34 -0400
> Byron Jeff <.....byronjeffspam_OUTspamclayton.edu> wrote:
>
>> Continues and breaks only work within certain constructs.
>
> Ok... The break would have taken you out of a for, if the if statement
> were inside a for:

Of course -- the 'break' is still inside a 'for' statement, if the 'if'
statement is inside a 'for' statement.

But if you textually replace "while" with "if", you can't guarantee that
the ex-'while'-now-'if' statement is enclosed in a statement that makes
the 'break' -- which previously was legal in the ex-'while' statement --
to still be legal.

> This is, of course, not an example of elegant programming, but could
> explain why the 'break' worked.

It is quite common to have the 'break' statements that are inside loops
inside 'if/else' constructs. Unconditional 'break' statements inside
loops are the exception (and usually not an example of elegant
programming :)

Gerhard

2009\08\28@101949 by rolf

flavicon
face
So I got to thinking about this some more... and the first option:

> #define while if
> #define continue
> #define break

has issues as well, because you can have statements like:

do {
   ....
} while ( ...);

and the #define while if is insufficient to keep that working...

just a thought..

Rolf

On Mon, 24 Aug 2009 18:25:57 -0400, "M. Adam Davis" <TakeThisOuTstienman.....spamTakeThisOuTgmail.com>
wrote:
{Quote hidden}

>> --

2009\08\28@113342 by Bob Ammerman

picon face
How about:

#define if(c) while(c) if(c)

This effectively turns the 'if' into a 'while' while still allowing an
'else' clause without an error.

It has the added advantage(?) of changing the meaning of any 'break' or
'continue' statements inside the 'then' or 'else' clauses of the 'if'.

-- Bob Ammerman
RAm Systems

2009\08\28@124922 by William \Chops\ Westfield

face picon face

On Aug 28, 2009, at 8:33 AM, Bob Ammerman wrote:

> How about:
>    #define if(c) while(c) if(c)

Man, you guys are confusing "bonehead" with <censored>...

("bonehead move" generally meaning that you accidentally do something  
stupid to yourself.  Which is much different that being intentionally  
malicious!)

BillW

More... (looser matching)
- Last day of these posts
- In 2009 , 2010 only
- Today
- New search...