Skip to main content

discriminator_c_width

Function discriminator_c_width 

Source
pub fn discriminator_c_width(
    ast: &Ast,
    discriminator: Id<TypeNode>,
) -> (&'static str, &'static str)
Expand description

How a union’s switch and its case labels have to be spelled in C and C++.

switch ((long long) …) with case <v>LL: is right for every signed discriminator and wrong for one case that is in the corpus: union Choice switch (unsigned long long) { case 16045690984833335998: … } does not fit a long long, so the label is a constant the compiler refuses — integer constant is so large that it is unsigned, and then an error. The generated probe does not build at all.

It is a real gap and not a hypothetical: union-discriminator-ulonglong is a corpus case, and every emitter that writes a switch over a discriminator had this. Found through the CORBA column’s decode probe, which is the first one to compile that case.

Returns ("unsigned long long", "ULL") for an unsigned discriminator and ("long long", "LL") for everything else. An enumeration is signed — E1 — and so is char.