GLBasic forum

Main forum => GLBasic - en => Topic started by: MrPlow on 2019-May-09

Title: Inline C++
Post by: MrPlow on 2019-May-09
I must be doing something wrong but my tries at using past examples of C++ inline code is not working...
is the way I am doing it?

Getting errors like so...
"C:/../..Printtest/stdio.h:39:24: no include path in which to search for stdio.h
C:\Users\..\..\Local\Temp\glbasic\gpc_temp0.cpp:101: error: expected constructor, destructor, or type conversion before ';' "

Code: GLBasic [Select]
GOSUB main

SUB main:
INLINE
}
#include <stdio.h>

 namespace __GLBASIC__{
ENDINLINE

printf1()

PRINT "HELLO",100,100
SHOWSCREEN
KEYWAIT
ENDSUB




FUNCTION printf1:
 INLINE

   char z[100] = "I am learning C programming language.";
 
   printf("%s", z);
 
   RETURN 0;


ENDINLINE


ENDFUNCTION
Title: Re: Inline C++
Post by: dreamerman on 2019-May-09
hm.. shoudn't it be something like this:
Code: GLBasic [Select]
INLINE
        }
                extern "C" {
                        #include <cstdio>
                }
        namespace __GLBASIC__ {
ENDINLINE
Title: Re: Inline C++
Post by: MrPlow on 2019-May-09
Tried that too just getting./..

gpc_temp0.cpp:53:17: stdio: No such file or directory
Title: Re: Inline C++
Post by: dreamerman on 2019-May-09
Another thing that INLINE shouldn't be in main source file (not sure about this), so this will work:
main source:
Code: GLBasic [Select]
GOSUB main

SUB main:

printf1()

PRINT "HELLO",100,100
SHOWSCREEN
KEYWAIT
ENDSUB
 
second file:
Code: GLBasic [Select]
INLINE
        }
                extern "C" {
                        #include <cstdio>
                }
        namespace __GLBASIC__ {
ENDINLINE


FUNCTION printf1:

INLINE

   char z[100] = "I am learning C programming language.";
 
   printf("%s", z);
   
   return 0;
   
ENDINLINE

ENDFUNCTION
 

Take a note that printf writes to standard output stream, so either app should be compiled as console application, use other function as GLBasic debug doesn't catch stdout info (not sure) or write output to file for example with such batch command in Windows (write file as *.bat):
Code: GLBasic [Select]
inline_test.exe >>stdout.txt
Title: Re: Inline C++
Post by: MrPlow on 2019-May-09
Okay, tried that too and got these errors...

C:\Users\Lenovo\AppData\Local\Temp\glbasic\gpc_temp1.cpp:16:18: cstdio: No such file or directory
C:\Users\Lenovo\AppData\Local\Temp\glbasic\gpc_temp1.cpp: In function `DGInt __GLBASIC__::printf1()':
C:\Users\Lenovo\AppData\Local\Temp\glbasic\gpc_temp1.cpp:46: error: `printf' was not declared in this scope

Same result with <stdio> instead of <cstdio>

Title: Re: Inline C++
Post by: dreamerman on 2019-May-09
hm.. strange, before posting I checked that code with GLB 15 & 16.. low chance, but maybe that lib is missing, check in: 'GLBasic\Compiler\platform\Win32\Include'.
Or maybe I did forgot about something trivial  ;/
Problem appears with all projects using INLINE? (some complete projects from forum too)
Title: Re: Inline C++
Post by: MrPlow on 2019-May-09
Okay - getting further now..

There was no stdio.h in my include dir so I put one in there (4k in size - so not sure if it was the correct one)
also I changed
 #include <stdio.h>
to
 #include "stdio.h"

Now it compiles but does not understand printf() function.

UPDATE: Sorted this out > Issue was I had no headerfiles - copied them in and worked first time. Thnks!

Title: Re: Inline C++
Post by: dreamerman on 2019-May-10
What GLB version You are using? On v16 include files are in different path that in v15 (that I posted previously). Maybe some system environment variable was wrongly set, did You tried different GLB versions or reinstalling GLB?

in GLB v15:
cstdio -> 4.26KB
stdio.h ->14.7KB
Title: Re: Inline C++
Post by: Schranz0r on 2019-May-10
Do you guys use the headerfiles-pack?
Title: Re: Inline C++
Post by: Heiko on 2019-May-10
btw. are the headers up to date? do they still fit the current version of the glb version? gcc / g++ (5.30) are from 2015 and the header from 2010.
Should we copy the headers to win32 and win64 folder?Because in the header package is only the win32 folder.Maybe needs that an update.In the next days i would try some INLINE things.
Title: Re: Inline C++
Post by: Schranz0r on 2019-May-10
Gernot?  :-[
Title: Re: Inline C++
Post by: bigsofty on 2019-May-10
You could put all your header file references within a C header file, then link it at the projects command line in the projects options. The headers will be available to any inline code after that point.