Inline C++

Previous topic - Next topic

MrPlow

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
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

dreamerman

hm.. shoudn't it be something like this:
Code (glbasic) Select
INLINE
        }
                extern "C" {
                        #include <cstdio>
                }
        namespace __GLBASIC__ {
ENDINLINE
Check my source code editor for GLBasic - link Update: 20.04.2020

MrPlow

Tried that too just getting./..

gpc_temp0.cpp:53:17: stdio: No such file or directory
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

dreamerman

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
Check my source code editor for GLBasic - link Update: 20.04.2020

MrPlow

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>

Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

dreamerman

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)
Check my source code editor for GLBasic - link Update: 20.04.2020

MrPlow

#6
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!

Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

dreamerman

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
Check my source code editor for GLBasic - link Update: 20.04.2020

Schranz0r

Do you guys use the headerfiles-pack?
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Heiko

#9
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.

Schranz0r

Gernot?  :-[
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

bigsofty

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.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)