0

In a C++ header file I found this line:

_showroot = char(val)

(val is an int variable)

and later:

return(int(_showroot))

(inside a function of type int)

The header is part of the FLTK toolkit. What does that syntax mean? It seems to be a type casting, but shouldn't it use the syntax "(char)val" instead of "char(val)"? Are the two equivalent, or is there a difference?

angros47
  • 49
  • 1
  • 6
  • It's equivalent: https://en.cppreference.com/w/cpp/language/explicit_cast – UnholySheep Jun 10 '22 at 18:21
  • They're [equivalent ways](https://en.cppreference.com/w/cpp/language/explicit_cast) of doing the same C-style cast. One difference is that you can do `(unsigned int)val` but not `unsigned int(val)` because of how tokens with spaces are handled. – Nathan Pierson Jun 10 '22 at 18:21
  • It's a **function-style cast**. – Pete Becker Jun 10 '22 at 20:27

0 Answers0