public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ulyssesric at yahoo dot com dot tw" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/21834] Error when passing unsigned long long as function arguments
Date: Tue, 31 May 2005 03:38:00 -0000	[thread overview]
Message-ID: <20050531033555.20947.qmail@sourceware.org> (raw)
In-Reply-To: <20050531001655.21834.ulyssesric@yahoo.com.tw>


------- Additional Comments From ulyssesric at yahoo dot com dot tw  2005-05-31 03:35 -------
Fine, I'll list all codes if you insist:

#include <avr/io.h>

typedef unsigned char           byte_t;
typedef unsigned long long      qword_t;

void uart_init(void)
{
    // 115200 & 8N1
    UBRR1H = 0x00;
    UBRR1L = 0x08;
    UCSR1A |= (0x01<<U2X1);
    UCSR1C = 0x06;
    UCSR1B &= ~0x04;
    UCSR1B |= ((0x01<<RXEN1) | (0x01<<TXEN1));
}

void uart_putchar(byte_t octet)
{
    UDR1 = octet;
    while (!(UCSR1A & (0x01<<UDRE1)));
}

void uart_write(byte_t *octet, uint8_t len)
{
    while (len--) {
        UDR1 = *octet++;
        while (!(UCSR1A & (0x01<<UDRE1)));
    }
}

void foo( byte_t state, qword_t srcAddr, byte_t routeOptions, qword_t dstAddr )
{
    uart_putchar(state);
    uart_write((byte_t *)(&srcAddr),8);
    uart_putchar(routeOptions);
    uart_write((byte_t *)(&dstAddr),8);
}

void main(void) {
    uart_init();
    foo(0x00,0x1234ll,0x01, 0x5678ll);
    while(1);
}

and the output is:

D1,
34,12,D1,D1,D1,D1,D1,D1,
01,
AB,CD,00,CF,00,80,00,78

in hexdecimal format. Obviously it's incorrect.

If I change the code to:

#include <avr/io.h>

typedef unsigned char           byte_t;
typedef unsigned long long      qword_t;

void uart_init(void)
{
    // 115200 & 8N1
    UBRR1H = 0x00;
    UBRR1L = 0x08;
    UCSR1A |= (0x01<<U2X1);
    UCSR1C = 0x06;
    UCSR1B &= ~0x04;
    UCSR1B |= ((0x01<<RXEN1) | (0x01<<TXEN1));
}

void uart_putchar(byte_t octet)
{
    UDR1 = octet;
    while (!(UCSR1A & (0x01<<UDRE1)));
}

void uart_write(byte_t *octet, uint8_t len)
{
    while (len--) {
        UDR1 = *octet++;
        while (!(UCSR1A & (0x01<<UDRE1)));
    }
}

void foo( qword_t srcAddr, qword_t dstAddr, byte_t state, byte_t routeOptions )
{
    uart_putchar(state);
    uart_write((byte_t *)(&srcAddr),8);
    uart_putchar(routeOptions);
    uart_write((byte_t *)(&dstAddr),8);
}

void main(void) {
    uart_init();
    foo(0x1234ll,0x5678ll,0x00,0x01);
    while(1);
}

And the output will be:

00,
34,12,00,00,00,00,00,00,
01,
78,56,00,00,00,00,00,00

Compiling Procedure:

avr-gcc -mmcu=atmega128 -g -Os -Wall -Wa,-adhlns=main.lst -std=gnu99 -funsigned-char 
-funsigned-bitfields -fpack-struct -fshort-enums -ffreestanding -Wl,-Map=main.map -Wl,--cref  
main.c -o main.elf
avr-objcopy -O ihex -R .eeprom test.elf test.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 
-O ihex test.elf test.eep
avr-objdump -h -S test.elf > test.lss
avr-nm -n test.elf > test.sym

Programming with AVR Studio 4.11 build 401, JTAGICE mkII


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21834


  parent reply	other threads:[~2005-05-31  3:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-31  1:22 [Bug c/21834] New: " ulyssesric at yahoo dot com dot tw
2005-05-31  3:35 ` [Bug target/21834] " pinskia at gcc dot gnu dot org
2005-05-31  3:38 ` ulyssesric at yahoo dot com dot tw [this message]
2005-05-31  3:41 ` ulyssesric at yahoo dot com dot tw
2005-06-19 14:02 ` pinskia at gcc dot gnu dot org
     [not found] <bug-21834-10737@http.gcc.gnu.org/bugzilla/>
2007-05-30 20:29 ` eweddington at cso dot atmel dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050531033555.20947.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).