Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Unexpected and difficult to understand SIGSEGV Date: Sun, 04 Oct 2015 17:57:03 -0700 Organization: None to speak of Lines: 50 Message-ID: References: <8362e3dd-17c5-4d88-a88f-5116ea0f10e0@googlegroups.com> <9256d7fa-5b3e-4183-b071-d910254623ce@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="27747"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xMFCLmo/OBWw7pD1DWq/M" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:jirF6R3oVTq5T8yqtPNQjoJimbs= sha1:VujEaie3Exl7oijct8PVZBUr/TM= Xref: csiph.com comp.lang.c:71909 Richard Damon writes: > On 10/4/15 6:01 PM, Keith Thompson wrote: >> Tim Rentsch writes: >> > Keith Thompson writes: >> >> [snip] >> >> >> >> I *think* it's accurate to say that two integer types are >> >> compatible if and only if they're the same type. >> > >> > Do you mean to exclude enumerated types? Enumerated types >> > are compatibile with a signed or unsigned integer type (or >> > char), but are nonetheless distinct types. >> > >> > If enumerated types are excluded, I believe the statement >> > is right. >> >> You're right, I glossed over enumerated types. (Actually I forgot >> that they're classified as "integer types"; I should have checked.) >> >> Actually, that raises a question. Given: >> >> enum foo { zero, one, two }; >> >> let's assume that the compiler chooses to make `enum foo` compatible >> with unsigned. Is there a practical difference between `enum >> foo` being *compatible* with unsigned vs. being the *same type* >> as unsigned (similar to a typedef)? Is there a C program that >> would behave differently if `enum foo` and unsigned were the same >> type rather than being distinct but compatible types? >> > One big one, pointers, an enum foo* is a distinct type to unsigned*, and > not at all interchangable. Actually, given that enum foo and unsigned are compatible, enum foo* and unsigned* are also compatible. For example, this is valid (and gcc at least doesn't complain about it): enum foo { zero, one, two }; void func(enum foo); void func(unsigned); enum foo obj = zero; unsigned *ptr = &obj; -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"