Path: ...!3.eu.feeder.erje.net!feeder.erje.net!news.in-chemnitz.de!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.c Subject: Re: enums and switch vs function calls Date: 5 Apr 2025 11:26:32 GMT Organization: Stefan Ram Lines: 23 Expires: 1 Mar 2026 11:59:58 GMT Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de CqKTc4RDB/8zDYR6TEmmWwyOBx0KbUbdLv7GEuOPSCEkb7 Cancel-Lock: sha1:cU9f4zM/WfhqSOp2Hk/TyFAogJg= sha256:wGy/NmZhCViiukGHhJplHzikEaPMhnHfaIUSuLhmHDs= X-Copyright: (C) Copyright 2025 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en-US Bytes: 1973 Richard Harnden wrote or quoted: >int hex = colour_to_hex(10); >... then the compiler doesn't complain that 10 is not in the enum. >Why? Surely the compiler can tell. I get | |error: enum conversion when passing argument 1 of 'colour_to_hex' is invalid in C++ [-Wc++-compat] | |int hex = colour_to_hex(10); | | ^~ |note: expected 'enum colour' but argument is of type 'int' | | int colour_to_hex(enum colour colour) | | ^~~~~~~~~~~~~ | with gcc -Wc++-compat .