Author Topic: How correctly synchronize interruption with raster [CPCTelera]  (Read 4187 times)

0 Members and 1 Guest are viewing this topic.

Offline pelrun

  • Supporter
  • 6128 Plus
  • *
  • Posts: 661
  • Country: au
    • index.php?action=treasury
  • Liked: 349
  • Likes Given: 217

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!


Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.900
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1112
  • Likes Given: 1879

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

Offline pelrun

  • Supporter
  • 6128 Plus
  • *
  • Posts: 661
  • Country: au
    • index.php?action=treasury
  • Liked: 349
  • Likes Given: 217
"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.
« Last Edit: 04:24, 12 January 16 by pelrun »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.900
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1112
  • Likes Given: 1879
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

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 911
  • Liked: 443
  • Likes Given: 73
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.

Offline pelrun

  • Supporter
  • 6128 Plus
  • *
  • Posts: 661
  • Country: au
    • index.php?action=treasury
  • Liked: 349
  • Likes Given: 217
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.)


Online reidrac

  • Supporter
  • 6128 Plus
  • *
  • Posts: 905
  • Country: gb
  • Trying to gamedev!
    • index.php?action=treasury
    • usebox.net
  • Liked: 1667
  • Likes Given: 896
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 and Brick Rick for the CPC.

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