Jump to content
Sign in to follow this  
Mike Schafer

Interesting Behavior Of ~ Operator

Recommended Posts

I have students using BoostC and they manage to make some interesting errors. This one seems strange to me. (We are using l1.9.3 beta target 16F877)

 

Student wrote:

 

void main(void)

{

char k;

k = 0;

~k;

}

 

instead of

 

void main(void)

{

char k;

k = 0;

k = ~k;

}

 

Both compile fine, but only the second one links. Looking at the assembly, the former with the error just stops generating code at the ~k; line. I'm not sure if this is a bug or not.

 

Another issue is with the used of capital C as a variable. The following doesn't compile (says missing semicolon at the void main(void) line.) Changing the variable name solves the problem. What is special about C as a variable name, and are there others like it?

 

void main(void)

{

char C;

C = 0;

}

 

Best Regards,

 

Mike

Share this post


Link to post
Share on other sites
void main(void)

{

char k;

k = 0;

~k;

}

 

    instead of

 

void main(void)

{

char k;

k = 0;

k = ~k;

}

 

Both compile fine, but only the second one links. Looking at the assembly, the former with the error just stops generating code at the ~k; line. I'm not sure if this is a bug or not.

 

Yes this is a bug. Now fixed. Fix will be available in the next release.

 

Another issue is with the used of  capital C as a variable. The following doesn't compile (says missing semicolon at the void main(void) line.) Changing the variable name solves the problem. What is special about C as a variable  name, and are there others like it?

 

void main(void)

{

char C;

C = 0;

}

 

Did you forget to mention that there also was #include <system.h> in this code? This code compiles fine but if you use system.h compilation fails because C is defined in system header as a constant and constants can't be used as l-values.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
void main(void)

{

char k;

k = 0;

~k;

}

 

    instead of

 

void main(void)

{

char k;

k = 0;

k = ~k;

}

 

Both compile fine, but only the second one links. Looking at the assembly, the former with the error just stops generating code at the ~k; line. I'm not sure if this is a bug or not.

 

Yes this is a bug. Now fixed. Fix will be available in the next release.

 

Another issue is with the used of  capital C as a variable. The following doesn't compile (says missing semicolon at the void main(void) line.) Changing the variable name solves the problem. What is special about C as a variable  name, and are there others like it?

 

void main(void)

{

char C;

C = 0;

}

 

Did you forget to mention that there also was #include <system.h> in this code? This code compiles fine but if you use system.h compilation fails because C is defined in system header as a constant and constants can't be used as l-values.

 

Regards,

Pavel

 

 

Pavel,

 

My bad. Should have looked more closely at the include file. That is exactly it.

 

I'm starting to get a message saying the alpha release expirese in 5 days. We

hava a C2C academic license that I use in a course that I am teaching. This year

we switched to BoostC. Is our ability to use it going to expire before I can upgrade or purchase an academic license to BoostC?

 

Mike

Share this post


Link to post
Share on other sites

Mike,

 

Is our ability to use it going to expire before I can upgrade or purchase an academic license to BoostC?

 

Its time that you upgraded to the latest beta release.

Its available for free.

 

Regards

Dave

Share this post


Link to post
Share on other sites
Mike,

 

Is our ability to use it going to expire before I can upgrade or purchase an academic license to BoostC?

 

Its time that you upgraded to the latest beta release.

Its available for free.

 

Regards

Dave

 

Dave

 

I'm running IDE version 5.8 and BoostC Optimizing C Complier

Version 1.9.3 Beta (for PIC18 architecture) so I thought I had the latest

version.

 

Mike

Share this post


Link to post
Share on other sites

Mike,

 

I thought you have an older version because of the message saying "alpha version expires in 5 days" (message must be incorrect).

 

A new version will be release very soon, best to wait for that one then.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Dave,

 

I will wait to the new version.

 

I am having a very strange problem with the linker, and I haven't been able

to isolate it to where I can post it here.

 

The code complies, but the linker fails with an unable to resolve lable message.

If I remove a header file with some function prototypes in it (none of which are

callled), it llinks successfully. If I leave the header in, and change the type of variables in the main program from short to unsigned short, it links. If I remove a line that says

val = a << b; (all declared as short), it links. I haven't been able to reduce it to a minimal set of lines that links under one set of conditions, and not under others.

 

If you would like, I can e-mail you the files so you can take a look at it.

 

Regards,

 

Mike

Share this post


Link to post
Share on other sites

Mike,

 

If you would like, I can e-mail you the files so you can take a look at it.

PLease send the project exhibiting the fault support@picant.com.

 

Anything you do to reduce the complexity of the project would help.

 

Regards

Dave

Share this post


Link to post
Share on other sites
Mike,

 

If you would like, I can e-mail you the files so you can take a look at it.

PLease send the project exhibiting the fault support@picant.com.

 

Anything you do to reduce the complexity of the project would help.

 

Regards

Dave

 

Dave,

 

Problem went away with the new release.

 

Thanks.

 

Regards,

 

Mike

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...