This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Struct error

Hi,

I'm trying to port code written for the CROSSWORKS_ARM_COMPILER to C51 and Keil will not accept the following definition:

        typedef struct _FFS_FILE
{
        DWORD directory_entry_sector;
        BYTE directory_entry_within_sector;
        DWORD current_cluster;
        BYTE current_sector;
        WORD current_byte;
        DWORD current_byte_within_file;
        DWORD file_size;

        union
        {
                struct
                {
                        unsigned int file_is_open                               :1;
                        unsigned int read_permitted                             :1;
                        unsigned int write_permitted                    :1;
                        unsigned int write_append_only                  :1;
                        unsigned int inc_posn_before_next_rw    :1;
                        unsigned int access_error                               :1;
                        unsigned int end_of_file                                :1;
                        unsigned int file_size_has_changed              :1;
                        unsigned int reserved                                   :8;
                } bits;
                WORD word;
        } flags;

} FFS_FILE;

I get this error:
ffs.h(131): error C141: syntax error near 'DWORD'
ffs.h(131): error C129: missing ';' before 'directory_entry_sector'

I'm not well versed in C and any help will be appreciated. Thanks,

John

  • BYTE, WORD and DWORD aren't reserved data types in C.

    So you need to include a header file that contains them. Or define them yourself.

    #include <stdint.h>
    
    typedef uint8_t BYTE;
    typedef uint16_t WORD;
    typedef uint32_t DWORD;
    

    Or if the compiler doesn't have stdint.h then the following works for a lot of compilers for 32-bit and smaller processors - but may get incorrect size depending on the actual size of short,int,long used by the compiler:

    typedef unsigned char BYTE;
    typedef unsigned short WORD;
    typedef unsigned long DWORD;
    

  • Per,

    Thank you, your suggestion worked. Apparently, Keil C51 does not have stdint.h but the definition of standard types did the trick.

    Thanks again,
    John