-2

all

I have a few problems with using structures.
The source is shown below.

main.c

#include <stdio.h>
#include "info.h"

_Rbuffer Rb;

void write(_Rbuffer Rb *rb)
{
    printf("write function\n");
}


void main(void)
{

    printf("Hello World\n");

}

info.h

#include <stdint.h>

typedef struct
{
    uint8_t Button1;
} _Rbuffer;

extern _Rbuffer Rb;

When compiling, the following error occurs.

root@test-VirtualBox:~/sample# gcc main.c
main.c:6:24: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
 void write(_Rbuffer Rb *rb)
                        ^  
root@test-VirtualBox:~/sample# 

I am currently unable to change info.h.

I declare a structure and I do not know why an error occurs.

How do I fix this?

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
DonBit
  • 223
  • 2
  • 11
  • 10
    `_Rbuffer Rb *rb` makes no sense. What are you trying to declare? (Note also that the name `_Rbuffer` is reserved for the implementation. Programs are not allowed to use names that begin with an underscore and capital letter.) – Raymond Chen Jun 08 '17 at 02:08
  • 1
    What you have is basically `int a * b`, which is a syntax error, as you see. Either `write(_Rbuffer Rb)` or `write(_Rbuffer *rb)` would compile. Whether this is what you want, though, I haven't a clue. – Ken Y-N Jun 08 '17 at 02:08
  • Names starting underscore followed by capital letter are reserved for implementation use. Also, if you intend to use posix code, you shouldn't call your function `write` – M.M Jun 08 '17 at 02:12

2 Answers2

1

1 You should use int main instead of void main .

2 You should use void write(_Rbuffer *rb) instead of void write(_Rbuffer Rb *rb) .

Yunbin Liu
  • 1,484
  • 2
  • 11
  • 20
  • It is not obvious what kind of system this is for, so 1) is a pointless comment. `void main (void)` is fine and standard-compliant on freestanding systems. – Lundin Jun 08 '17 at 06:37
  • @Lundin "The definition void main() is not and never has been C++, nor has it even been C." https://stackoverflow.com/a/2080996/7671328 – Yunbin Liu Jun 08 '17 at 06:54
  • That particular quote is actually infamous for being very much incorrect. Stroustrup is confused over many language details... The truth is found in the standard, [see this](https://stackoverflow.com/a/31263079/584518). – Lundin Jun 08 '17 at 07:06
  • @Lundin Thank you for you advice. But I am confused. And I will use `int main` instead of `void main` in the future. – Yunbin Liu Jun 08 '17 at 07:58
  • Roughly, it can be summarized as `int main (...)` is the correct form to use on hosted systems (running on OS) and versions like `void main (void)` is the correct form to use on freestanding systems (embedded systems/microcontrollers). C and C++ are quite similar here. Stroustrup was ignorant of the existence of embedded systems when he made that failed comment. – Lundin Jun 08 '17 at 08:01
0
void write(_Rbuffer Rb *rb)
{
printf("write function\n");
}

you passed in Rb, but you also pointed at *rb

if you want to modify Rb, then

void write(_Rbuffer* Rb)

if you just want to a copy of your Rb, then

void write (_Rbuffer Rb)
Lambert T
  • 1
  • 1
  • 1