Jump to content
Sign in to follow this  
pacosoide

Pointers In Boostc

Recommended Posts

:blink: How can I use a pointer in boostc.

 

I declared these variables

 

int value;

int *pvalue;

 

I tried compiling this expression and it fails.!

 

pvalue=@value;

 

 

How would you do this in BoostC, if possible.

Thanks, Jose.

Share this post


Link to post
Share on other sites

Jose,

 

you need to use the standard 'C' syntax:

 

int value;

int *pvalue;

 

pvalue= &value;

 

 

Regards

Dave

Share this post


Link to post
Share on other sites
Jose,

 

you need to use the standard 'C' syntax:

 

int value;

int *pvalue;

 

pvalue= &value;

 

 

Regards

Dave

 

Thanks Dave, my question was incomplete and here is the rest. I do see my syntax error there.

What I want to do is place two char variables in the int variable value.

Let's say

 

char vara, varb;

int value;

int *pvalue

pvalue=&value;

*pvalue=vara;

*(pvalue + 1)=varb;

Would that code place the two variables into the int variable value?

Thanks in advance. Jose DeMoya

Share this post


Link to post
Share on other sites

Jose,

 

void main()
{
   int value;
   char* pvalue;
   pvalue=(char*)&value;
   *pvalue= 0x34;
   *(pvalue + 1)= 0x12;
   
   while( 1 ); // wait forever
}

 

If you just want to convert to two chars to and integer, there are much more efficient ways to do this, eg:

 

void main()
{
int value;
value = (0x12 << 8) + 0x34;

while( 1 ); // wait forever
}

 

Regards

Dave

Share this post


Link to post
Share on other sites

The system header of the latest BoostC release 2.2 includes a macro that does exactly what you ask for. It makes a 16 bit long value from two 8 bit long values and does this using very efficient code:

 

unsigned short s; unsigned char c1, c2;
...
s = MAKESHORT(c1,c2);

More information about this macro can be found in the BoostC help file.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
The system header of the latest BoostC release 2.2 includes a macro that does exactly what you ask for. It makes a 16 bit long value from two 8 bit long values and does this using very efficient code:

 

unsigned short s; unsigned char c1, c2;
...
s = MAKESHORT(c1,c2);

More information about this macro can be found in the BoostC help file.

 

Regards,

Pavel

Thanks very much, I enjoyed very much the second piece of code with the shifting the high byte and then adding the second half.

Jose.

Share this post


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...
Sign in to follow this  

×
×
  • Create New...