CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

an oddity with ones complement or TTWIW?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

an oddity with ones complement or TTWIW?
PostPosted: Mon Jan 19, 2009 9:38 am     Reply with quote

PCM ver 4.066

the ones complement seems odd - or perhaps its me

for the following simple case

unsigned int8 myvar=7;

myvar=~myvar; // generates COMF assembler as desired

~myvar; //
// and
~~myvar; // generates NEITHER an error NOR the desired COMF opcode
// NO code produced at in the LST file for either form

// meanwhile
myvar~; // and
myvar~~; // both generate an error 'expecting ;'


is it ME or the compiler ???
Ttelmah
Guest







PostPosted: Mon Jan 19, 2009 12:32 pm     Reply with quote

It wouldn't. You are not putting the result into a variable, so the optimiser removes the lines...
It is a bit like saying:

myval+1;

Again no code will be generated.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jan 20, 2009 9:26 am     Reply with quote

sorry - i guess i was stuck under the impression that 1's complementing was a unitary operation in the exact same category as ++var or --var, which don't need a reassignment to work - since there is an underlying assembler, single cycle opcode for it .
That and the lack of an error when i try ~~var .

i guess you are maybe saying TTWIW is the real answer, since there is no reason a compiler couldn't be made to recognize ~~ and treat it like ++, -- etc.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Jan 20, 2009 12:49 pm     Reply with quote

What would you expect ~~var to do? Would it be the same as ~(~var) which would do nothing?

++ and -- have clear meanings, but ~~ is not clear to me.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 20, 2009 3:06 pm     Reply with quote

Vs. 4.066 generates a warning. You need to enable warnings.
Quote:
>>> Warning 207 "pcm_test.c" Line 12(1,1): Code has no effect


MSVC 6.0 generates a similar warning if you try a similar program with it:
Quote:
warning C4552: '~' : operator has no effect;


Test program:
Code:
#include <16F877.h>
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//========================
void main()
{
int8 value;

~value;

while(1);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group