I want to read characters from the console and check if it is alpha numeric. From my understanding, isalnum
has the following function signature.
int isalnum(int x);
Why is it illegal to write
switch(input) { case isalnum(input): ...
if isalnum
returns an integer value.
See https://en.cppreference.com/w/c/language/switch
The syntax requires
case constant_expression : statement
with
constant_expression - a constant expression of the same type as the type of condition after conversions and integral promotions
I.e. syntax requires constant expression.
The result of a function call is not a constant expression.
That is why it is illegal.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments