EmbeddedRelated.com
Forums

function call

Started by Juergen August 31, 2006
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

> 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 * * * *
Juergen <juergenschlinker@gmx.de> 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 (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.