Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any writef() format specifier for a bool?

Tags:

chapel

I looked at the writef() documentation for any bool specifier and there didn't seem to be any.

In a Chapel program I have: ...

config const verify = false;
/* that works but I want to use writef() to also print a bunch of other stuff*/
writeln("verify = " + verify); 
writef("verify = %<what-specifier-goes-here>\n", verify);

This last statement works ok.

// I guess I could do:

writef( "verify = %s\n",if verify then "true" else "false");
like image 353
Michael Merrill Avatar asked Nov 11 '17 22:11

Michael Merrill


People also ask

What is the format specifier for bool?

There is no format specifier to print boolean type using NSLog. One way to print boolean value is to convert it to a string. Another way to print boolean value is to cast it to integer, achieving a binary output (1=yes, 0=no).

How do I print a boolean in C++?

Use std::boolalpha in cout to Print Boolean Values in C++ If it's set to true , it displays the textual form of Boolean values, i.e. true or false , but when it is set to false , we get bool output as 0 and 1 only.

Which one is a format specifier for boolean value in Golang?

Use %t to format a boolean as true or false .

Is bool a datatype in C?

C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true.


1 Answers

Based on the FormattedIO documentation, there is not a bool specifier available in Chapel's formatted IO.

Instead, you can use the generic specifier (%t) to print bool types in formatted IO:

config const verify = false;
writef("verify = %t\n", verify);

This specifier utilizes the writeThis or readWriteThis method of the type to print the variable. The Chapel IO documentation provides more details on how these methods work.

like image 153
ben-albrecht Avatar answered Sep 27 '22 16:09

ben-albrecht