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

[SOLVED] Syntax question (One can awkward)

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



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

[SOLVED] Syntax question (One can awkward)
PostPosted: Mon Sep 24, 2007 6:42 am     Reply with quote

Hello,

In some sample of code i read value followed by 'L'. here is an example from
code writing by PCM programmer :

Code:
frequency = (int16)(1000000L / current_ccp_delta);


What mean the 'L' at the and of '1000000L' ??

I can not found that in manual ?

Thank-you.

dro.
_________________
in médio virtus


Last edited by inservi on Mon Sep 24, 2007 8:45 am; edited 3 times in total
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Sep 24, 2007 7:50 am     Reply with quote

L stands for a long number. When you need to use a fixed number in an intermediate step in a mathematical expression and you don't want the compile to default the precision you can give specify the precision with L.
Ex if you don't want the compiler to assume 112 as an 8 bit number then you would use 112L
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Mon Sep 24, 2007 7:56 am     Reply with quote

Thank-you very much.

Is there other possibilities than L, maybe F for float ?

dro.
_________________
in médio virtus
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Mon Sep 24, 2007 8:06 am     Reply with quote

I believe L is notational and it is not equivalent to declaring something as int16. The value 1000000L since it is internal to a mathematical expression should get 32 bit scratch storage. You don't give us the declaration of current_ccp_delta but if it is 32bit then the division will have the precision of 32 bits before casting down to 16 bits.
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Mon Sep 24, 2007 8:45 am     Reply with quote

Thank-you, now it is clear for me.

dro.
_________________
in médio virtus
Ttelmah
Guest







PostPosted: Mon Sep 24, 2007 9:18 am     Reply with quote

For float, just add a decimal point.
In the example given:

1000000L

The 'L' is doing nothing. Since the value is large enough to force the number to be a 'long' already. Where 'L' is important, is in things like:
Code:

int8 val1;
int16 val2;

val2=val1*100;


The problem here, is that since _both_values to the right of the '=', are implicity 'int8' types (since this is the default type), the multiplication will be done using 'int8' arithmetic. If instead you use:
Code:

val2=val1*100L;


This forces the use of int16 arithmetic.

Similarly:
Code:

val2=val1*100.0;


Will force floating point arithmetic to be used.

Best Wishes
inservi



Joined: 13 May 2007
Posts: 128

View user's profile Send private message

PostPosted: Mon Sep 24, 2007 10:51 am     Reply with quote

Thank you Ttelmah.

dro.
_________________
in médio virtus
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