Tue Feb 25, 2020 3:42 am
Login Register Lost Password? Contact Us


Returing references to STRINGs from C++

Questions around writing code and queries

Tue Feb 11, 2020 5:44 pm Change Time Zone

Hi,

I'm attempting to return an address into a STRING from some C++, I have:
Code: Select all
STRING SplitUp(CONST STRING dat) := BEGINC++
    __result = dat;
    return;
ENDC++;

SplitUp('Abc');

But the compiler complains with:
Code: Select all
Error:    invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive] (24, 15), 6003, W20200211-172713_1.cpp


But, for once, I've actually read the ECL Ref Manual, where it states:

A function that takes a string parameter should also have the type prefixed by const in the ECL code so that modern
compilers don't report errors when constant strings are passed to the function.


Same Error if I leave out the CONST.

Err what am I doing wrong?
Cheers

Allan
Allan
 
Posts: 419
Joined: Sat Oct 01, 2011 7:26 pm

Tue Feb 11, 2020 10:04 pm Change Time Zone

Allan,
Err what am I doing wrong?
IMO, nothing! :)

I tried every way I could and got the same error in every instance, although this example with a BOOLEAN return type works fine:
Code: Select all
BOOLEAN isUpper(const string mystring) := BEGINC++
  size_t i=0;
  while (i < lenMystring)
  {
    if (!isupper((byte)mystring[i]))
        return false;
    i++;
  }
  return true;
ENDC++;
isUpper('JIM');
isUpper('Sue');
So I am of the opinion that it's most likely the combination of a STRING parameter and a STRING return type that's bollixing things up here.

Please submit a JIRA on this issue. :)

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1519
Joined: Wed Oct 26, 2011 7:40 pm

Wed Feb 12, 2020 7:40 am Change Time Zone

Allan
 
Posts: 419
Joined: Sat Oct 01, 2011 7:26 pm


Return to Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest