Hayo!
Look what I found.
C Ternary conditional operator failure or parser error - who knows.
C Ternary conditional operator is/was: A ? B : C
It doesn't matter about the code, but about LOGIC.
This code works compiled with compiler named:
Tiny C Compiler.
This code is not working compiled with GCC, even
Online Compiler.
Code fragment: (Works on Tiny C, Doesn't works on GCC)
if(*node!=0)
{
return TernaryNode_add(((*node)->value < *name) ? &(*node)->left : ((*node)->value == *name) ? &(*node)->middle : &(*node)->right,++name,data);
};
Problem is that - gcc it seems does not parse that Ternary operator correctly.
GCC compatible version of code? - YES!
This is GCC compatible version that works:
if(*node!=0)
{
TernaryNode ** test = ((*node)->value < *name) ? &(*node)->left : ((*node)->value == *name) ? &(*node)->middle : &(*node)->right;
return TernaryNode_add(test,++name,data);
};
Function TernaryNode_add description:
Function adds a word to a Ternary tree.
Returns (-1) on managed error or if a word exists already.
Returns (0) on success - word added.
Original code:
I am creating a Ternary tree to add words.
While creating I found that Ternary C operator is not working in the way you see above - It does not parses it correctly if that my ternary operator thingy is put in first argument (Maybe it's too large or too boring for gcc).
I am adding two equal words, gcc produces error but other compiler result is correct.
You can try it your self with that online compiler link provided above, files are attached here below.
If code works it must print:
(rvalue: -1)
All Right, All Left!Bame
Rvalue is -1 because I tried to add one word twice.
Edit:
Bye, don't use GCC if you still have hairs on hour head.
[SOLVED] Bye, GCC is awesome! Edit, again:
SOLVED, LRESULT: Paremeter Evaluation Issue of C (Left to Right or Right to Left)