09 October 2023, 17:34 | #1521 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
It is more like : Code:
int somecode (int val, int other_param) { int xx,yy,ret; if (val) { ret = xx = side_effect1(other_param); } if (val <= 0) { ret = yy = side_effect2(other_param); } if (val < 0) { ret = yy - xx; } return ret; } |
|
09 October 2023, 17:51 | #1522 | |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
I trust xx and yy are initialised before the tests? Otherwise the compiler warning is correct. |
|
09 October 2023, 18:29 | #1523 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
09 October 2023, 19:59 | #1524 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,764
|
C# does this too, which is odd for clear cases like this.
This doesn't compile (it's not even a warning in C#, just an error): Code:
int a; int b = Environment.TickCount; if (b == 0) a = 1; if (b < 0) a = 2; if (b > 0) a = 3; Console.WriteLine(a); Code:
int a; int b = Environment.TickCount; if (b == 0) a = 1; else if (b < 0) a = 2; else a = 3; Console.WriteLine(a); |
09 October 2023, 20:05 | #1525 | |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
OK yes, looking again I see there's no case where the third condition can execute without both the previous two having executed, so xx and yy are guaranteed to have a value by the time they're added. |
|
09 October 2023, 20:13 | #1526 | |
Registered User
Join Date: May 2023
Location: Norwich
Posts: 378
|
Quote:
Obviously that's a Windows centric article, but the principle remains the same regardless of OS. Even if you write assembly language, your program is supposed to remain within the constraints of the ABI. It won't necessarily fail if it doesn't, but you have wandered into the realm of "undefined behaviour" nonetheless. |
|
09 October 2023, 20:17 | #1527 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,764
|
|
09 October 2023, 20:39 | #1528 | |||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
Quote:
Quote:
Actually that guy in the blog is probably just plain wrong even in the case of Windows. He is apparently confusing the language - which may do stack unwinding - with the operating system. I'm not Windows internals specialist, but nevertheless... Frankly, just compile a C program : there are no exceptions there, no stack unwinding of any sort. In C++ compiler settings you can even disable exceptions, to remove said stack unwinding. And i can tell you for a fact that at least AmigaOS does not give a shit about what you put in your program's stack. Anyway this is completely off. That D0-D1/A0-A1 are not scratch in some parts of an asm program, is totally different of what's in the stack. The ABI only says what registers are supposed to be altered in case of an OS call, and this does not even apply to all OS functions. |
|||
09 October 2023, 21:45 | #1529 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,764
|
|
09 October 2023, 21:48 | #1530 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
The best compiler warning I ever saw came out of vbcc when compiling a Duff's Device example. It said, and I quote "This code is weird."
|
09 October 2023, 22:09 | #1531 | ||
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
Quote:
|
||
09 October 2023, 23:31 | #1532 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
It looks quite stupid that the OS does stack unwinding in the place of the compiler. It might however still be true in the case of Windows (which is rather crazy OS) and it could be interesting to disassemble some code to see what it does with the stack ; however, one 100% complete sure thing is that AmigaOS does *not* do anything like that. Neither do Atari TOS or MacOS 68k. |
|
09 October 2023, 23:51 | #1533 | |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
Quote:
All tried with -Wall -Wextra How do you get a warning? |
|
10 October 2023, 00:16 | #1534 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
10 October 2023, 10:44 | #1535 | ||
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
Quote:
|
||
10 October 2023, 11:57 | #1536 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
The "Argument from authority" card is best used when dealing with a viewpoint that is inscrutable in some way, e.g. the case for a religious edict for which the only basis is "because it says so".
It's less well applied in cases where the position you are arguing against can be tested or validated in some way. Using it to downplay someone's claim in this way amounts to saying "I know better than you and your expertise/experience in this area is irrelevant.". There's a reason someone is considered an expert in a given area. And while it's true that they can still be wrong, on the balance of probability it would be hubris to disregard their opinion for simply having that expertise. |
10 October 2023, 12:12 | #1537 | ||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
If what he says is true, then the program isn't free of what it puts in the stack and even languages with no support for exceptions at all should do things for supporting the OS ones. Doesn't this sound plain crazy ? I have few disassembly experience for windows, and the few i have traces back a few decades, but it did not suggest anything like that. If the code omits the frame pointer, which i think is an option most compilers have, how can the OS possibly unwind the stack, knowing it could point to anything ? Quote:
Search the web about stack unwinding : you will find many articles from many sources, but it is all about runtimes and specific languages, not operating systems. I found nothing to back up this assertion. It has next to zero logic. It contradicts all personal experience i have. It is wrong for all platforms i know well. But you're right at some point : yes it can be validated. So let's disassemble code and see what it does with the stack... |
||
10 October 2023, 12:16 | #1538 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
that's a good one. And yet it's entirely sensible in a way. A private destructor without any friends that can invoke it makes any instance of it it tricky to dispose of.
|
10 October 2023, 12:35 | #1539 | ||
Registered User
Join Date: May 2023
Location: Norwich
Posts: 378
|
Quote:
Quote:
FWIW, on everything but 32-bit x86, unwind codes are used rather than frame pointers to unwind exceptions: https://learn.microsoft.com/en-us/cp...?view=msvc-170 |
||
10 October 2023, 13:12 | #1540 | ||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
They don't have to care at all about what's in the stack. When an instruction fails to access memory, be it due to real error or some paging, the only useful information is the instruction itself. It may then trigger an exception, or some page load from disk and a restart of said instruction. Quote:
Besides, they don't say what happens for programs who just don't want to catch any exception. All this said, your original argument was for Amiga and we clearly see all we have here just does not apply there. |
||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Chat GPT Amiga Assembly | rcman | Coders. Asm / Hardware | 3 | 26 March 2023 20:24 |
An Amiga coder was banned without a reason - is it ok? | litwr | project.EAB | 1 | 18 June 2021 20:38 |
Beginning Amiga Assembly Tutorial(s) | Curbie | Coders. Asm / Hardware | 15 | 29 May 2020 00:21 |
Beginning Amiga Assembly Programming | Hewitson | Coders. Tutorials | 32 | 09 October 2012 18:25 |
Amiga Assembly sources - Please help! | W4r3DeV1L | Amiga scene | 21 | 16 July 2008 08:13 |
|
|