File: ternary.c

package info (click to toggle)
c2go 0.26.11-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,052 kB
  • sloc: ansic: 6,037; sh: 82; makefile: 5
file content (45 lines) | stat: -rw-r--r-- 822 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include "tests.h"

void f_empty(){
	return;
};

int main()
{
    plan(9);

    int a = 'a' == 65 ? 10 : 100;
    float b = 10 == 10 ? 1.0 : 2.0;
    char *c = 'x' == 5 ? "one" : "two";
    char d = a == 100 ? 'x' : 1;

    is_eq(a, 100);
    is_eq(b, 1);
    is_streq(c, "two");
    is_eq(d, 'x');

	is_false(0 ? 1 : 0);
	is_false(NULL ? 1 : 0);
	is_true('x' ? 1 : 0);

    a = a == 10 ? b == 1.0 ? 1 : 2 : 2;

    if (a == (a == 2 ? 5 : 10))
    {
	fail(__func__);
    }
    else
    {
	pass(__func__);
    }

	diag("CStyleCast <ToVoid>")
	{double a, b; 0 ? (void)(a) : (void)(b); (void)(a),(void)(b); }
	{double a   ; 0 ? (void)(a) : f_empty(); (void)(a);}
	{double    b; 0 ? f_empty() : (void)(b); (void)(b);}
	{           ; 0 ? f_empty() : f_empty(); }
	pass("Ok - ToVoid");

    done_testing();
}