BASIC

Author Topic: Inline C++  (Read 432 times)

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1456
    • View Profile
Inline C++
« 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
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 288
    • View Profile
    • my personal website
Re: Inline C++
« Reply #1 on: 2019-May-09 »
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

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1456
    • View Profile
Re: Inline C++
« Reply #2 on: 2019-May-09 »
Tried that too just getting./..

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

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 288
    • View Profile
    • my personal website
Re: Inline C++
« Reply #3 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
Check my source code editor for GLBasic - link

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1456
    • View Profile
Re: Inline C++
« Reply #4 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>

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

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 288
    • View Profile
    • my personal website
Re: Inline C++
« Reply #5 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)
Check my source code editor for GLBasic - link

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1456
    • View Profile
Re: Inline C++
« Reply #6 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.

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

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 288
    • View Profile
    • my personal website
Re: Inline C++
« Reply #7 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
Check my source code editor for GLBasic - link

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5014
  • O Rly?
    • View Profile
Re: Inline C++
« Reply #8 on: 2019-May-10 »
Do you guys use the headerfiles-pack?
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Heiko

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 498
    • View Profile
Re: Inline C++
« Reply #9 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.
« Last Edit: 2019-May-10 by Heiko »
Ryzen 5 2400G - MSI B450 Tomahawk

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5014
  • O Rly?
    • View Profile
Re: Inline C++
« Reply #10 on: 2019-May-10 »
Gernot?  :-[
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2613
    • View Profile
Re: Inline C++
« Reply #11 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.
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)