??? const ??

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
despx
Posts: 78
Joined: 10 Aug 2006 17:11

??? const ??

#1 Post by despx » 09 Feb 2011 02:24

Hi,
if I write:

Code: Select all

const char pippo = 10;
OK Compiler set a char costant pippo to value 10.

but

Code: Select all

cost pippo = 10;
compiler non send me error but pippo is also a char or signed char?

And if I write:

Code: Select all

const pippo = 32000;
pippo is int or unsugned?


Bye
Despx

braus
Posts: 167
Joined: 25 Jul 2007 22:55
Location: Mexico, city.

Re: ??? const ??

#2 Post by braus » 09 Feb 2011 03:42

MikroC is a hardly typed language (in order to accomplish ANSI C standard) so, when you declare a single variable you have to assign it an arithmetic type, this is true despite of compiler does not mark an error message
Best Regards
Omar Galicia
Mexico City

despx
Posts: 78
Joined: 10 Aug 2006 17:11

Re: ??? const ??

#3 Post by despx » 09 Feb 2011 10:27

Thanks for your reply!
If I have to convert the Pascal code:

Code: Select all

const pluto = 0x06;
In C I must write:

Code: Select all

#define pluto 0x06
or

Code: Select all

cost char pluto = 0x06
Apparently they do the same thing but I'm not sure. What is the right code?

Thanks.
Despx

DAJ
Posts: 105
Joined: 18 Dec 2010 11:39

Re: ??? const ??

#4 Post by DAJ » 09 Feb 2011 12:56

Dear dspx

1. Use of Types in mikroC.
May be useful to read the PDF manual, especially pages 167+ "TYPES", and pages 191+ "Type Conversions".

You will see that mikroC can do an "automatic implicit conversion of type" (p191). When it does this, the compiler may not issue a warning. I suspect that you have an example of this. (Please note that this implicit conversion of type is done in line with the ANSI C standard.)

Personally, I would prefer to get a warning when implicit conversion of type is performed. I recently raised the matter of warnings (in the context of function parameters) with MikroE. They said:
I have passed this on to the developers and they will decide if this is going to be included as an enhancement.
Thank you for your suggestion.
For more information, refer to - Post subject: Re: Implicite Conversion of Type for Function Parameters at:

http://www.mikroe.com/forum/viewtopic.php?f=88&t=28879

2. Pre-Processor
An answer to your question about "what is the right code?" (post 9 Feb) .... Your question is really one about C itself, rather than about the mikroC compiler in particular.

It seems to suggest that you do not have background knowledge of the C Pre-Processor because while the two code examples you gave can often have the similar numerical effects (for example if used within one source file) they are fundamentally different.

Should I be right, then if you have not already done so, may I suggest you read about it on p229+ of the mikroC pdf manual. The manual assumes a level of knowledge of C. (Please do not take offence if my assumption is incorrect. I've had a busy day!)

Hope this helps.

Post Reply

Return to “mikroC PRO for PIC General”