News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Arnaud

How correctly synchronize interruption with raster [CPCTelera]

Started by Arnaud, 20:58, 08 January 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pelrun

Quote from: AMSDOS on 23:46, 11 January 16

That's naughty!  :o


Not at all. That's exactly how they *should* be handled. (seriously, what's the alternative?)


If you want an example of funny variable handling, look at SDCC for 8051. There isn't really any stack, so all local variables are actually hidden globals unless you mark the function as needing reentrancy. Woo!


AMSDOS

Quote from: pelrun on 02:29, 12 January 16

Not at all. That's exactly how they *should* be handled. (seriously, what's the alternative?)


The alternative is to do it in-house, not globally.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

pelrun

"in-house"? If you're suggesting the compiler should generate code that dynamically allocates the static variable on function access, saves that pointer, and reuses it on subsequent access then you're suggesting something utterly ridiculous (also, where does that pointer get stored? In a "hidden" global? You've not replaced anything, just added a pointless wrapper.)


Variables (static/global/local) differ in two characteristics. Lifetime, and scope. Statics and globals have identical lifetime (infinite) but differing scopes (which means they all have to be allocated at program start), locals have different lifetimes (and so are allocated as and when those lifetimes start.) Therefore "x treats statics and globals identically except for visibility" isn't a design choice, it's just restating the definition.

AMSDOS

I'm not sure what your suggesting, all I'm saying is a compiler shouldn't take a Locally defined variable and make it global.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

andycadley

Quote from: AMSDOS on 03:28, 12 January 16
I'm not sure what your suggesting, all I'm saying is a compiler shouldn't take a Locally defined variable and make it global.
It doesn't, but the only difference in this case between the two is the scope in which it is accessible, which is an entirely artificial construct of the compiler anyway. As long as it doesn't allow you to access the variable outside of it's scope, then the behaviour is correct.

pelrun

Quote from: AMSDOS on 03:28, 12 January 16
I'm not sure what your suggesting, all I'm saying is a compiler shouldn't take a Locally defined variable and make it global.


Ah, that's where the misunderstanding is. Static variables in C aren't local variables, even if they're defined local to a function, and they're not global either. They're a distinct class which as mentioned before has the lifetime of a global but the scope of a local variable. Allocation and initialisation are done purely based on the lifetime of the variable; scope doesn't matter (and isn't affected.)


reidrac

Just check the ASM code that SDCC generates and compare how it does it with a static variable in the function and using a global initialized variable. Then use the form that best suits your needs ;)

My experience with C is too often "high level" and I find reading the ASM code very educational. Sometimes is worth spending some time rewriting things just to find "the best C for SDCC".
Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

Powered by SMFPacks Menu Editor Mod