Path: ...!npeer.as286.net!npeer-ng0.as286.net!weretis.net!feeder8.news.weretis.net!newsfeed.xs3.de!ereborbbs.duckdns.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.c Subject: Re: 80386 C compiler Date: Tue, 26 Nov 2024 17:59:08 -0000 (UTC) Organization: A noiseless patient Spider Lines: 47 Message-ID: <20241125132021.212@kylheku.com> References: <20241125101701.894@kylheku.com> Injection-Date: Tue, 26 Nov 2024 18:59:10 +0100 (CET) Injection-Info: dont-email.me; posting-host="0e8a432a62a8fe15c431d060725152b9"; logging-data="3740784"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19h6iPIGhunTzLwGlRQ1MFQstFLClhQ74c=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:OV9hAuIFXwx23hcwcFNaTfLvjXo= Bytes: 2753 On 2024-11-25, Rosario19 wrote: > On Mon, 25 Nov 2024 18:23:58 -0000 (UTC), Kaz Kylheku wrote: > >>void fn(int a) >> { >> int x[3] = { foo(), bar(), a }; /* not in C90 */ > > is in the above foo() called before bar()? No, you cannot rely on that. Maybe it's fixed in a more recent standard, but C99 (which I happen to have open in a PDF reader tab) stated that "The order in which any side effects occur among the initialization list expressions is unspecified.". This implies that there is no sequence point between any two initializing expressions, which means we don't know whose expression's function call takes place first. In any case, a C90 compiler with the above support as an extension to C90 can specify rigid sequencing behavior. > void fn(int a) > { > int x[3]; > x[0]=foo(); x[1]=bar(); x[2]=a; > > this would be ok with every C compiler One problem is, if you're doing this because your compiler is C90, you also have to do something about all declarations which follow the int x[3], since they cannot occur after a statement. You can add another level of block nesting for them, or whatever. Initialization is preferable to leaving an object uninitialized and assigning. There is a scope where the name is visible, but the object is not initialized, inviting code to be inserted there which tries to use it. If I needed foo to be called before bar, I would still rather do the following than assignment: int f = foo(); int b = bar(); int x[3] = { f, b, a }; -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca