vishapoberon / compiler

vishap oberon compiler
http://oberon.vishap.am
GNU General Public License v3.0
186 stars 25 forks source link

passing VAR s: POINTER TO ARRAY OF CHAR passes compilation but later doesn't compile in C #94

Open norayr opened 3 years ago

norayr commented 3 years ago

in case we have function with this signature:

PROCEDURE Get*(VAR s: POINTER TO ARRAY OF CHAR);

it compiles to:

export void modulename_Get (struct {
        ADDRESS len[1];
        CHAR data[1];
} **s);

void modulename_Get (struct {
        ADDRESS len[1];
        CHAR data[1];
} **s)
{
...

and then C compiler doesn't compile the generated C code with the following error:

modulename.c:16:25: warning: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
   16 | export void modulename_Get (struct {
      |                         ^~~~~~
modulename.c:22:18: warning: anonymous struct declared inside parameter list will not be visible outside of this definition or declaration
   22 | void modulename_Get (struct {
      |                  ^~~~~~
modulename.c:22:6: error: conflicting types for ‘modulename_Get’
   22 | void modulename_Get (struct {
      |      ^~~~~~~~~~
modulename.c:16:13: note: previous declaration of ‘modulename_Get’ was here
   16 | export void modulename_Get (struct {
      |             ^~~~~~~~~~
C compile: gcc -fPIC -g -I "/opt/voc/2/include"  -c modulename.c
norayr commented 3 years ago

same without VAR by the way. left here to look at this one day.

diegosardina commented 3 years ago

in case we have function with this signature:

PROCEDURE Get*(VAR s: POINTER TO ARRAY OF CHAR);

This procedure is not usable in Oberon-2 because that type is anonymous (and it looks like the same in C today).