1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

function call

Discussion in 'Embedded' started by Juergen, Aug 31, 2006.

  1. Juergen

    Juergen Guest

    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
     
    Juergen, Aug 31, 2006
    #1
    1. Advertisements

  2. Juergen

    FreeRTOS.org Guest

    > 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 * * * *
     
    FreeRTOS.org, Aug 31, 2006
    #2
    1. Advertisements

  3. Juergen <> 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 (-aachen.de)
    Even if all the snow were burnt, ashes would remain.
     
    Hans-Bernhard Broeker, Aug 31, 2006
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Rebel7254
    Replies:
    3
    Views:
    1,227
    Rebel7254
    Jun 26, 2003
  2. Eli Billauer
    Replies:
    0
    Views:
    388
    Eli Billauer
    Oct 30, 2003
  3. Neo
    Replies:
    17
    Views:
    546
    CBFalconer
    Jan 21, 2005
  4. Alex Vinokur
    Replies:
    4
    Views:
    910
    Alex Vinokur
    Feb 27, 2006
  5. yaoxinwen
    Replies:
    2
    Views:
    527
    Tim Wescott
    Mar 1, 2006
  6. vjay

    Function call mechanism in c

    vjay, Jul 12, 2007, in forum: Embedded
    Replies:
    4
    Views:
    386
  7. BillW50
    Replies:
    2
    Views:
    1,033
    Richard Bonner
    Jun 29, 2010
  8. Aaron
    Replies:
    0
    Views:
    1,004
    Aaron
    Jun 28, 2010
Loading...