bcc icon indicating copy to clipboard operation
bcc copied to clipboard

Strings in inlined functions are NOT defined in generated header files

Open GWRon opened this issue 1 year ago • 0 comments

When marking a function as inline you cannot use a string in there as the generated code forgets to emit the string to the ".h"-file:

Example:

SuperStrict
Framework Brl.StandardIO

Function _inlinedFunction:String() inline
	Return "This String is not defined in C"
End Function

Rem
'this would also fail!
Function _inlinedFunction:String() inline
	Local s:String = "This String is Not defined in C"
	Return s
End Function
EndRem

Print _inlinedFunction()

Error:

In file included from /home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/.bmx/untitled4.bmx.gui.release.linux.x64.c:1:
/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled4.bmx: In function ‘_m_untitled4__inlinedFunction’:
/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled4.bmx:6:29: error: ‘_s0’ undeclared (first use in this function)
    6 |         Return "This String is not defined in C"
      |                             ^~~
/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled4.bmx:6:29: note: each undeclared identifier is reported only once for each function it appears in

C:

#include "untitled4.bmx.gui.release.linux.x64.h"
struct BBString_31{BBClass_String* clas;BBULONG hash;int length;BBChar buf[31];};
static struct BBString_31 _s0={
	&bbStringClass,
	0x46692efb1b556783,
	31,
	{84,104,105,115,32,83,116,114,105,110,103,32,105,115,32,110,111
	,116,32,100,101,102,105,110,101,100,32,105,110,32,67}
};
#line 5 "/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled4.bmx"
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
extern BBSTRING _m_untitled4__inlinedFunction();
#else
BBSTRING _m_untitled4__inlinedFunction(){
	#line 6 "/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled4.bmx"
	return ((BBString*)&_s0);
}
#endif
static int _bb_main_inited = 0;
int _bb_main(){
	if (!_bb_main_inited) {
		_bb_main_inited = 1;
		__bb_brl_blitz_blitz();
		__bb_brl_standardio_standardio();
		#line 16 "/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled4.bmx"
		brl_standardio_Print(_m_untitled4__inlinedFunction());
		return 0;
	}
	return 0;
}

H:

#ifndef TMP_UNTITLED4_BMX_GUI_RELEASE_LINUX_X64_H
#define TMP_UNTITLED4_BMX_GUI_RELEASE_LINUX_X64_H

#include <brl.mod/blitz.mod/.bmx/blitz.bmx.release.linux.x64.h>
#include <brl.mod/standardio.mod/.bmx/standardio.bmx.release.linux.x64.h>
int _bb_main();
#line 5 "/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled4.bmx"
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
inline BBSTRING _m_untitled4__inlinedFunction(){
	#line 6 "/home/ronny/Arbeit/Tools/BlitzMaxNG/tmp/untitled4.bmx"
	return ((BBString*)&_s0);
}
#else
BBSTRING _m_untitled4__inlinedFunction();
#endif

#endif

My GCC:

 $ gcc -dM -E - < /dev/null | grep __STDC_VERSION__ | awk '{ print $2 " --> " $3 }'
__STDC_VERSION__ --> 201710L

So it will go into the ".h" file and there the string (_s0) is not known as it is only defined in the C file.

GWRon avatar Oct 29 '24 10:10 GWRon