Motherboard Forums


Reply
Thread Tools Display Modes

function call

 
 
Juergen
Guest
Posts: n/a
 
      08-31-2006, 08:00 AM
Hi,

I am a little confused by the following example:

portCHAR myaddress = 0xFF;
ReadRegister(myaddress);
void ReadRegister(portSHORT address);

The compiler isn't giving me a warning for using a portCHAR(8 bit) as a
parameter when portSHORT(16 bit) is used.
But even though I expected the compiler to do "something" and assign
0x00FF to address, this was not the case.
Inside the function ReadRegister "address" is 0x??FF with ?? being
something undeterministic.
It is not "auto-casting" to 0x00FF.
I am fine with this functionality ... but I don't get it why there is
no compiler warning.
Any ideas?

thanks in advance

Juergen

I am using
cpu: MSP430xF1611
gcc: msp430-gcc 3.3.6
gdb: msp430-gdb 5.1.1
OS: linux
embedded OS: freeRTOS

 
Reply With Quote
 
 
 
 
FreeRTOS.org
Guest
Posts: n/a
 
      08-31-2006, 08:41 AM
> Hi,
>
> I am a little confused by the following example:
>
> portCHAR myaddress = 0xFF;
> ReadRegister(myaddress);
> void ReadRegister(portSHORT address);
>
> The compiler isn't giving me a warning for using a portCHAR(8 bit) as a
> parameter when portSHORT(16 bit) is used.
> But even though I expected the compiler to do "something" and assign
> 0x00FF to address, this was not the case.
> Inside the function ReadRegister "address" is 0x??FF with ?? being
> something undeterministic.
> It is not "auto-casting" to 0x00FF.
> I am fine with this functionality ... but I don't get it why there is
> no compiler warning.
> Any ideas?
>


I think passing an 8bit type to a 16bit parameter would result in a silent
"integral promotion", and not result in a compiler warning by default. Take
care however regarding your sign. Whether the result was sign extended to
0xffff, or result in a positive 0x00ff is platform dependent, according to
the C standard.

Regards,
Richard.

+ http://www.FreeRTOS.org
+ http://www.SafeRTOS.com
for Cortex-M3, ARM7, ARM9, HCS12, H8S, MSP430
Microblaze, Coldfire, AVR, x86, 8051 & PIC18 * * * *


 
Reply With Quote
 
 
 
 
Hans-Bernhard Broeker
Guest
Posts: n/a
 
      08-31-2006, 09:43 PM
Juergen <(E-Mail Removed)> wrote:

> I am a little confused by the following example:


> portCHAR myaddress = 0xFF;
> ReadRegister(myaddress);
> void ReadRegister(portSHORT address);


That example is meaningless, as posted. It fails to compile, and
guessing how fix that compile error would be pointless. So: show
*actual*, complete code. Minimize it until the error almost goes
away.

> The compiler isn't giving me a warning for using a portCHAR(8 bit) as a
> parameter when portSHORT(16 bit) is used.


If at least the order of those three lines in the real source code is
as posted, that's to be expected --- at the time of that call, the
compiler hadn't seen the declaration of ReadRegister yet, so it had no
reason to complain about the argument's type. It does hint that you
probably didn't raise your compiler's warning level high enough,
though. If you had, you'ld have gotten a different warning than what
you expected, but a warning nevertheless: for calling a function
without any prototype declaration in sight.

> But even though I expected the compiler to do "something" and assign
> 0x00FF to address, this was not the case.


That expectation was wrong, and shows a lack of basic C knowledge.
You should consider retracing several steps in your C textbook, back
to where it talks about integer conversions.

--
Hans-Bernhard Broeker ((E-Mail Removed)-aachen.de)
Even if all the snow were burnt, ashes would remain.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Make laptop function keys behave like desktop function keys BillW50 Laptops 2 06-29-2010 10:58 AM
Re: Make laptop function keys behave like desktop function keys Aaron Laptops 0 06-28-2010 06:37 PM
function call with arguments which takes no arguments Neo Embedded 17 01-21-2005 10:58 AM
[ANN] cdepend - function call mapping of C projects Eli Billauer Embedded 0 10-30-2003 11:49 PM
Re: R96025 pure function call runtime error..ATI dvd... Rebel7254 ATI 3 06-26-2003 04:41 PM


All times are GMT. The time now is 05:07 AM.


Welcome!
Welcome to Motherboard Point
 

Advertisment