Author Topic: DIM FUNCTION Foo  (Read 75 times)

Robert

  • Hero Member
  • *****
  • Posts: 555
    • View Profile
DIM FUNCTION Foo
« on: January 02, 2021, 04:13:03 PM »
Code: [Select]

 DIM FUNCTION Foo$(a$)
 
 TYPE MyType                                 
   DYNAMIC A$[]
   DYNAMIC FN[] AS Foo_TYPE
   B AS INTEGER
 END TYPE
 
 DIM mt AS MyType
 
 REDIM mt.A$[2]
 REDIM mt.FN[3]
 
 mt.A$[0] = "Hello "
 mt.A$[1] = "World"
 mt.FN[0] = LCASE$
 mt.FN[1] = MCASE$
 mt.FN[2] = UCASE$
 
 PRINT mt.FN$[0](mt.A$[0]), mt.FN$[0](mt.A$[1])
 PRINT mt.FN$[1](mt.A$[0]), mt.FN$[1](mt.A$[1])
 PRINT mt.FN$[2](mt.A$[0]), mt.FN$[2](mt.A$[1])


CLang errors
Code: [Select]

snip.cpp:380:12: error: assigning to 'Foo_TYPE' (aka 'char *(*)(char *)') from incompatible type 'char *(LPCTSTR)'
      (aka 'char *(const char *)'): type mismatch at 1st parameter ('char *' vs 'LPCTSTR' (aka 'const char *'))
  mt.FN[0]=lcase;
           ^~~~~
snip.cpp:381:12: error: assigning to 'Foo_TYPE' (aka 'char *(*)(char *)') from incompatible type 'char *(LPCTSTR)'
      (aka 'char *(const char *)'): type mismatch at 1st parameter ('char *' vs 'LPCTSTR' (aka 'const char *'))
  mt.FN[1]=mcase;
           ^~~~~
snip.cpp:382:12: error: assigning to 'Foo_TYPE' (aka 'char *(*)(char *)') from incompatible type 'char *(LPCTSTR)'
      (aka 'char *(const char *)'): type mismatch at 1st parameter ('char *' vs 'LPCTSTR' (aka 'const char *'))
  mt.FN[2]=ucase;
           ^~~~~
3 errors generated.

MSVC errors
Code: [Select]
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.9.0-pre.2.0
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
Compiling "snip.cpp"..........
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29617 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

snip.cpp
snip.cpp(380): error C2440: '=': cannot convert from 'char *(__cdecl *)(LPCTSTR)' to 'Foo_TYPE'
snip.cpp(380): note: This conversion requires a reinterpret_cast, a C-style cast or function-style cast
snip.cpp(381): error C2440: '=': cannot convert from 'char *(__cdecl *)(LPCTSTR)' to 'Foo_TYPE'
snip.cpp(381): note: This conversion requires a reinterpret_cast, a C-style cast or function-style cast
snip.cpp(382): error C2440: '=': cannot convert from 'char *(__cdecl *)(LPCTSTR)' to 'Foo_TYPE'
snip.cpp(382): note: This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Linking ................
Microsoft (R) Incremental Linker Version 14.28.29617.0
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : fatal error LNK1181: cannot open input file 'snip.obj'
Finished!

Pelles C errors
Code: [Select]
Setting 64-bit environment for Pelles C...
Compiling "snip.c"..........
snip.c(376): warning #2145: Using incompatible types 'char * __cdecl (*)(const char *)' and 'Foo_TYPE (aka char * __cdecl (*)(char *))'.
snip.c(377): warning #2145: Using incompatible types 'char * __cdecl (*)(const char *)' and 'Foo_TYPE (aka char * __cdecl (*)(char *))'.
snip.c(378): warning #2145: Using incompatible types 'char * __cdecl (*)(const char *)' and 'Foo_TYPE (aka char * __cdecl (*)(char *))'.
snip.c(214): warning #2135: Static 'Foo' is not referenced.
Linking ................
Finished!
[/code]

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 714
    • View Profile
Re: DIM FUNCTION Foo
« Reply #1 on: January 02, 2021, 05:31:52 PM »
DIM FUNCTION Foo$(a as LPCTSTR)

Robert

  • Hero Member
  • *****
  • Posts: 555
    • View Profile
Re: DIM FUNCTION Foo
« Reply #2 on: January 02, 2021, 07:14:40 PM »
DIM FUNCTION Foo$(a as LPCTSTR)

Thanks, your mod will be applied to the example which is from the BCX Help file.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 714
    • View Profile
Re: DIM FUNCTION Foo
« Reply #3 on: January 02, 2021, 08:04:35 PM »
Function and argument types must match the definitions that BCX emits to the C/C++file.