Menu

#3676 error using structs in macros

open
nobody
None
Front-end
5
2023-11-20
2023-11-20
Under4Mhz
No

The following code fails to compile using sdcc, but succeeds with gcc:

/// GPL 2.0 or later
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

void dotest(void) {}

typedef struct {

    uint8_t count;

} TestData;

TestData testData;

#define for8( var, size ) unsigned char var; for ( (var) = 0; (var) < (size); (var)++ )

void for1test(void) {

    for8(count,testData.count)
    {
        dotest();
    }
}

// sdcc -mz80 ./forbug.c -c
$ sdcc -mz80 ./forbug.c -c
./forbug.c:20: error 26: '' not a structure/union member
gcc ./forbug.c -c -Wall
sdcc -v
SDCC : z80/sm83/z80n/mos6502 TD- 4.3.6 #14442 (Linux)

Discussion

  • Philipp Klaus Krause

    This is unrelated to the macro: the issuecan be reproduced using this variant:

    void dotest(void);
    
    typedef struct {
        unsigned char count;
    } TestData;
    
    TestData testData;
    
    void for1test(void) {
        unsigned char count;
        for (count = 0; count < testData.count; count++ )
            dotest();
    }
    
     

    Last edit: Philipp Klaus Krause 2023-11-20
  • Philipp Klaus Krause

    • Category: other --> Front-end
     

Log in to post a comment.

MongoDB Logo MongoDB