Jump to content

Passing An Ushort And Greater Than Or Equal To


Recommended Posts

1) How the hell do you handle this? i shouldnt have to look at the asm to find this out

 

void radio_wr_cmd(WORD cmddata)

{

BYTE lo, hi;

 

LOBYTE(lo, cmddata);

HIBYTE(hi, cmddata);

 

radio_wr_byte( (cmddata>>8)&0xFF ); // doesnt work

radio_wr_byte( (hi ); // doesnt work either

}

 

2) i cant believe the compiler has a bug in this for(i=10;i>=0;i++).....i mean its a cheap compiler but this should be handled properly; anybody had this problem before?

Link to post
Share on other sites
1) How the hell do you handle this? i shouldnt have to look at the asm to find this out

 

void radio_wr_cmd(WORD cmddata)
{
  BYTE lo, hi;

  LOBYTE(lo, cmddata);
  HIBYTE(hi, cmddata);

  radio_wr_byte( (cmddata>>8)&0xFF ); // doesnt work
  radio_wr_byte( (hi ); // doesnt work either
}

 

2) i cant believe the compiler has a bug in this for(i=10;i>=0;i++).....i mean its a cheap compiler but this should be handled properly; anybody had this problem before?

 

Perhaps if you were not such a potty mouth you would get a better informed answer.

 

That you are as god made you you will have to settle for an answer from me.

 

This code complies and works as I would expect:

 

// File: bug15.C
// Target: PIC16F648A
// OS: WinXP, SP2
// SourceBoostIDE: 6.55
// Compiler: BoostC 6.55
// Reproducible: never
// Expected behavior:  
//
// Description: 
//
// Claim that shift right 8 bits and HIGHBYTE macro fail.
//
// Unable to reporduce failing case.
//
#include <system.h>

typedef unsigned int WORD;
typedef unsigned char BYTE;

static void radio_wr_byte( BYTE b_data )
{
 portb = b_data;
}

void radio_wr_cmd(WORD cmddata)
{
 BYTE lo, hi;

 LOBYTE(lo, cmddata);
 HIBYTE(hi, cmddata);

 radio_wr_byte( (cmddata>>8)&0xFF ); // works for me
 radio_wr_byte( (hi ) ); // works for me too
}

void main()
{
 trisb = 0;
 trisa = 0;
 portb = 0;
 porta = 0;

 radio_wr_cmd(0x1234);
}

 

As to your point number 2, for(i=10;i>=0;i++), if i is declared as char then BoostC treats i as unsigned. This differs from most of the C compilers I have worked with. The char data type is usually a signed data type. This may be an implementation choice. I do not recall that char must be implemented as signed by default.

 

In any case if you are depending on a specific behavior of a data type you need to be sure that it's declared the way you need it and not rely on the complier to use a particular method that could be implementation dependent.

 

Added comments:

 

After reading my post it occurred to me that implications of char being unsigned may not be obvious.

 

To state it directly if i is declared as unsigned then the expression i>=0 is always true.

Edited by cac001
Link to post
Share on other sites

"for(i=10;i>=0;i++)"

 

Did you mean:

 

for(i=10;i>=0;i--)

 

What you typed in will count 10,11,12 .. 127 then maybe -1 and stop or if it is unsigend, it will never stop.

 

What I wrote will count 10,9,8, ... 0 then maybe -1 and stop if i is signed.

 

 

The way you specified is ugly as maybe on some platform a char is 16-bits so the loop is dependent on the size of the variable.

 

As cac001 hinted, chill out man. Just spread the love and answers will come your way.

 

Peace and Love

Ted

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...