Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Richard Harnden Newsgroups: comp.lang.c Subject: enums and switch vs function calls Date: Sat, 5 Apr 2025 11:29:41 +0100 Organization: A noiseless patient Spider Lines: 26 Message-ID: Reply-To: nospam.harnden@invalid.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 05 Apr 2025 12:29:42 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ea52f8b2e3a437e493b2833fc00662c8"; logging-data="2023734"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tPo8FlMHN0UbStXI4n+iVZaYCon0GF/I=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:Vaw8YeQ4R2A8tvtDxxl2OCjX4KA= Content-Language: en-GB Bytes: 1490 If I have: enum colour {RED, GREEN, BLUE} int colour_to_hex(enum colour colour) { switch (colour) { RED: return 0xff0000; GREEN: return 0x00ff00; // BLUE: return 0x0000ff; } ... } .... then the compiler will warn me that I've missed a case in the switch statement. Which is good and very helpful. But if I do: 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.