Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ternary operator
#1
Can one also integrate the declaration of a library into a function?
The reason for the question is that I wrote a small program that allows one to use the tenary operator from C. If you could put the whole thing into a function, it might be useful for Basic. Maybe.  Huh

The Basic-Program:
Code: (Select All)

'Aufruf des tenaeren Operators in C - 30. Okt. 2023

Option _Explicit

'In QB64 mit "Declare Library" wie angegeben
Declare Library "D:\Lab\QuickBasic64\Extern-nicht-Basic\C-Aufruf\tenaerOp"
  Function tenaerOp& (ByVal N As Long, Byval X As Long)
End Declare

Dim As Long N, X

X = 77

Locate 3, 3
Input "Zahl: ", N

Locate 5, 3
Print Using "Ausgabe: ###"; tenaerOp&(N&, X&)

End

The C part:
Code: (Select All)
//TenaerenOperator von Basic aufrufen - 30. Okt. 2023

#include <stdio.h>
#include <stdlib.h>

long tenaerOp(long eingabe, long x)
{
    long ausgabe;
        
    ausgabe = x > eingabe ? 100 : 200;
    return(ausgabe);    
}
Reply


Messages In This Thread
Ternary operator - by Kernelpanic - 10-30-2023, 09:57 PM
RE: Ternary operator - by DSMan195276 - 10-30-2023, 10:45 PM
RE: Ternary operator - by bplus - 10-30-2023, 11:08 PM
RE: Ternary operator - by Kernelpanic - 10-30-2023, 11:50 PM
RE: Ternary operator - by DSMan195276 - 10-31-2023, 01:13 AM
RE: Ternary operator - by Kernelpanic - 10-31-2023, 03:36 PM
RE: Ternary operator - by bplus - 10-31-2023, 01:37 AM
RE: Ternary operator - by DSMan195276 - 10-31-2023, 01:49 AM
RE: Ternary operator - by bplus - 10-31-2023, 02:02 AM



Users browsing this thread: 1 Guest(s)