0

Structs containing arrays in C51 are not allowed? After defining a simple structure in my C51 program,

struct RingBuffer 
{
    int zero;
    int size;
    int capacity;
    char data[10]; 
}; 

I got error:..\SOURCE\MYRINGBUFFER.H(25): error C141: syntax error near '['. It is clear that error is on the line with a char array defined in the struct(no errors after commenting).

Am I doing something wrong here? If not, is there anyway I can achieve what I'm attempting to do?

EDIT: All the code.

#ifndef __MY_RING_BUFFER_H__
#define __MY_RING_BUFFER_H__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct RingBuffer 
{
    int zero;
    int size;
    int capacity;
    char data[10]; 
};


#endif
Jongware
  • 22,200
  • 8
  • 54
  • 100
Razohux
  • 79
  • 9
  • 1
    How is `BUFFER_SIZE` defined? – M Oehm Jan 09 '16 at 18:45
  • If the compiler is not smart enough then the `+` may make it think the size as a dynamic value. – user3528438 Jan 09 '16 at 18:47
  • @MOehm, I suspected that, but it didn't work. In fact, the whole code only contains some includes at the top and this. – Razohux Jan 09 '16 at 18:52
  • I am not sure why this question would be voted for close, or even down voted. It adds value in the form of added insight for the users of C51 compilers on this site. OP question is clearly and concisely presented with evidence of some prior debugging and research. Although I originally commented that OP's answer should have been a comment, I now see that although it is short, it is a good answer. Again concise and clear. – ryyker Jan 09 '16 at 19:53

1 Answers1

4

I figured out what's wrong. data is a keyword in C51.

Razohux
  • 79
  • 9
  • 1
    @ryyker: definitely not as an edit in the original post. It would no longer be a question then. – Jongware Jan 09 '16 at 19:26
  • @Jongware - Yes, I see that now. And in fact, it is a perfectly relevant answer for what is also a good question. Thanks. – ryyker Jan 09 '16 at 19:48