April 20, 2024, 01:57:23 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Converting From C++

Started by Zen, December 17, 2006, 12:12:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zen

Hello.

I was reading some stuff in a C++ source file and I also use it in PHP too, but not sure how to convert it to Aurora. Here is the code in question...

return (Link==NULL || Link->Anchor)? NULL : Link;


Lewis

Ionic Wind Support Team

That is a ternary operator which is a shorthand IF statment.  It translates to:

if(Link==NULL || Link->Anchor)
     return NULL
else
     return Link;

Ionic Wind Support Team

Zen


Mike Stefanik

That's one of the things that is probably best left out of Aurora. While it's convenient, you can create some incredibly unreadable code with it and probably one of the most abused expressions in the C/C++ language.
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

J B Wood (Zumwalt)

I heavily agree, please leave ternary operators out.
I can't count the number of translations I have done where they threw me  off.

Barney

I never had problems with the ternary operator usage but it was usually in the form of the inline IF command in Clipper language, which was more readable than the C++ version. It's not the ternary operator that's bad but the way it tis written in certain languages.

RETURN IIF(Link==NULL OR Link->Anchor, NULL, Link)

Barney

Kale

Quote from: Mike Stefanik on December 17, 2006, 12:48:34 PM
That's one of the things that is probably best left out of Aurora. While it's convenient, you can create some incredibly unreadable code with it and probably one of the most abused expressions in the C/C++ language.

I like conditional expressions and IMHO they are extremely simple to understand and they can make code alot cleaner. :)

Mike Stefanik

December 18, 2006, 02:40:52 AM #7 Last Edit: December 18, 2006, 02:47:10 AM by Mike Stefanik
Yeah, sure. Until you see someone write something like this:


if ((a > 0 ? x = ((b !=c && d != e ? f-- : f++) && (g < 1 ? q++ : q = 0)) : x = q--) != 0)
{
....
}


That's not what I would exactly call "extremely simple to understand".

Edit: And before someone says that no one would actually write code that looks that bad, you would be wrong. When I used to do UNIX systems programming, I saw a lot of programs written that used constructs even more convoluted than that, complete with zero comments and variable names that were 1-2 characters all over the place.
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Zen

Yeah mike I think I agree there. At least if it is done with IF statements you can see it indented, so it is a lot easier to read. Thats just silly, I don't know why anyone would want to do that other than perhaps in a macro, so its all on one line.

Lewis

Zen

Ok I've now got some more stuff to convert :D

What do I do if a function returns a C++ class ??? Its not a .Net one or anything, just standard win32.

Lewis

Bruce Peaslee

Quote from: Barney on December 18, 2006, 01:47:26 AM
I never had problems with the ternary operator usage but it was usually in the form of the inline IF command in Clipper language, which was more readable than the C++ version. It's not the ternary operator that's bad but the way it tis written in certain languages.

RETURN IIF(Link==NULL OR Link->Anchor, NULL, Link)

Barney

I often put an IIF function for strings in my programs. It helps formatting.


sub main()
{
OpenConsole();
print("The answer is " + IIF(true,ÂÃ,  "True", "False") + ".");
print("The answer is " + IIF(false, "True", "False") + ".");
while GetKey()=="";
CloseConsole();
}

sub IIF(int bCondition, string sTrueString, string sFalseString), string
{
ÂÃ,  ÂÃ,  if(bCondition == true)
{
return sTrueString;
}
ÂÃ,  ÂÃ,  else
{
return sFalseString;
}
}


I first saw IIF() in a spreadsheet. I don't find this particular construction hard to read (although you could nest it enough to be so if you wantedÂÃ,  ;) ).
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

Quote from: Zen on December 18, 2006, 04:03:29 AM
Ok I've now got some more stuff to convert :D

What do I do if a function returns a C++ class ??? Its not a .Net one or anything, just standard win32.

Lewis

Is it a class, or a pointer to a class?  win32 has nothing to do with it.
Ionic Wind Support Team

Zen

The function returns a pointer to a class. I have the C++ class declarations for the class it points to.

Lewis

Ionic Wind Support Team

Then conversion should be easy. 

sub myfunction(),cmyclass *
{
     cmyclass *pRet = NEW(cmyclass,1);
     return pRet;
}
Ionic Wind Support Team

Zen

Ohh so all i need to do is convert the class definition to aurora and it should work? I didnt mean i need to return a pointer to a class. In the dll i am using there is a function that returns a c++ class.

Lewis

Ionic Wind Support Team

If it's a DLL then it would be a pointer to a class the DLL is returning.  I can't guarantee that will work for you in Aurora.  Depends on the complexity of the class being returned.  Our vtable follows the same format as C++ generally.

Paul.
Ionic Wind Support Team

Zen

Ok thanks Paul.

I will give it a go anyway.

Lewis