Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
FlapYoJacks
Feb 12, 2009

leper khan posted:

I just realized I could use setjmp longjmp to solve a problem I've been having.

What have I done.

You wrote bad code OP. There is never a reason to use longjmp unless you are doing some very hacky poo poo in bare-metal land.

edit: Maybe emulating exceptions is a valid excuse to use longjmp. Is that what you are trying to do?

FlapYoJacks fucked around with this message at 05:52 on Sep 27, 2023

Adbot
ADBOT LOVES YOU

Cybernetic Vermin
Apr 18, 2005

it is kind of fascinating that longjmp is a thing that exists as a standard. it is basically the impulse "eh, i'll just rewrite the stack and bit and set the program counter to where i wanted to be, what can really go wrong?" made into a really bad function.

there's almost no legitimate use of it of course, as you basically need to be in a place where you'd be comfortable just operating on that stuff directly *anyway*, and if you are in that position you're probably in a bit of software where you have the infrastructure for doing it more idiomatically.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

eschaton posted:

if setjmp and longjmp are somehow “solving” a problem for you, then something is seriously wrong with your approach

I'm trying to optimize out reads and writes to memory in a couple specific cases. I don't really have a choice on using the slow memory or not, since I don't have enough fast memory for my sim and I'd like to reserve it for the program stack.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.
Re: exceptions. Basically yes, I have a top level construct that executes through a queue and I want to early out the top level executor if I make a particular transition in one of the jobs.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

using longjmp in the right place is fine, you cowards

if you're already programming in C, why not take advantage of what few primitive are actually provided to you

tef
May 30, 2004

-> some l-system crap ->
i think it boils down to "if you have to ask, you probably don't need it"

Cybernetic Vermin
Apr 18, 2005

calling it "a primitive" is such a generous characterization of longjmp.

also simply don't code in c.

Armitag3
Mar 15, 2020

Forget it Jake, it's cybertown.


Cybernetic Vermin posted:

simply don't code, c, myeeeah

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Cybernetic Vermin posted:

calling it "a primitive" is such a generous characterization of longjmp.
well of course it is a language primitive, no more or less so than local goto keyword or signals or any other non-structured control flow mechanism that is part of the language

you can either use it well or use it poorly or choose to not use it at all, just like any other wrench in your toolbelt

Cybernetic Vermin posted:

also simply don't code in c.
I'm gonna do it, I'm gonna code in C!!!

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Cybernetic Vermin posted:

calling it "a primitive" is such a generous characterization of longjmp.

also simply don't code in c.

What other options do I have? I'd rather not write ASM and manually port to other architectures. And not all platforms I'm targeting have a C++ compiler.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

leper khan posted:

What other options do I have? I'd rather not write ASM and manually port to other architectures. And not all platforms I'm targeting have a C++ compiler.

If you were really set on a longjmp alternative you could consider some abstraction layer like libunwind (I'm sure there are others, too, this is just the one that came to mind)

or you could continue and just use longjmp for what by all accounts sounds like a reasonable use for it

e: or you could port your codebase to a superior language with continuations :smuggo:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Dijkstracula posted:

If you were really set on a longjmp alternative you could consider some abstraction layer like libunwind (I'm sure there are others, too, this is just the one that came to mind)

or you could continue and just use longjmp for what by all accounts sounds like a reasonable use for it

e: or you could port your codebase to a superior language with continuations :smuggo:

I need to read the programming manual for my compiler before I use setjmp. It might not support it lol.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

leper khan posted:

I need to read the programming manual for my compiler before I use setjmp. It might not support it lol.

if your compiler is standards-conforming it will as it's part of the language standard and not, like, a POSIX or GNU extension or something

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Dijkstracula posted:

if your compiler is standards-conforming it will as it's part of the language standard and not, like, a POSIX or GNU extension or something

It's from the 90s I'm not making assumptions

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

leper khan posted:

It's from the 90s I'm not making assumptions

yeah, fair, truly who could say in the wild world of (I'm assuming) ancient embedded software development

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Dijkstracula posted:

I'm gonna do it, I'm gonna code in C!!!

:mods:

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum
coding in C is the best, it’s how you make the spookiest code

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Sweeper posted:

coding in C is the best, it’s how you make the spookiest code

the reason for the season :spooky:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Dijkstracula posted:

yeah, fair, truly who could say in the wild world of (I'm assuming) ancient embedded software development

Ancient embedded software development for Japanese handheld game consoles. Special versions of dead compilers specific to whatever terrible barely unique processor.

The real solve is I need better hobbies.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

leper khan posted:

The real solve is I need better hobbies.
such as porting C compilers to ancient Japanese handheld game consoles :getin:

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Dijkstracula posted:

such as porting C compilers to ancient Japanese handheld game consoles :getin:

I know someone doing that and I'm unironically eagerly awaiting their efforts.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

out of curiosity, what's the hardware, are you posting updates to a project log or anything

akadajet
Sep 14, 2003

Sweeper posted:

coding in C is the best, it’s how you make the spookiest code

I still love this video
https://www.youtube.com/watch?v=Snr113r5ocY

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum
spookiest compiler flag? -ffast-math?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Dijkstracula posted:

out of curiosity, what's the hardware, are you posting updates to a project log or anything

Wonderswan and wonderswan color are my primary targets. Avoiding posting too much about the project because I haven't scrubbed all the unlicensed art out of it yet (only one thing left; I should just get that patched out)

I have working ports to a bunch of hardware. Ran into some issues with the neo geo pocket toolchain [compiler hard crashes on my project without logging anything] (which I really want to make work for cross play between ngp and dreamcast). There's some recent improvements in toolchains for pc engine, but I'm not sure if I'd be able to fit the game without the ram from supergrafx.

pseudorandom name
May 6, 2007

Dijkstracula posted:

using longjmp in the right place is fine, you cowards

if you're already programming in C, why not take advantage of what few primitive are actually provided to you

you should be using getcontext/setcontext/makecontext/swapcontext instead

The_Franz
Aug 8, 2003

pseudorandom name posted:

you should be using getcontext/setcontext/makecontext/swapcontext instead

those are pretty slow though, just roll your own fast stack swapping code for every arch

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

Sweeper posted:

spookiest compiler flag? -ffast-math?

-w

Kazinsal
Dec 13, 2011


Sweeper posted:

spookiest compiler flag? -ffast-math?

-Ofast. really should be called -Ounsafe

Armitag3
Mar 15, 2020

Forget it Jake, it's cybertown.


-Onoooooo

Achmed Jones
Oct 16, 2004



gotta -Ofast

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
-Wall is kinda spooky because it leaves many warnings spookily turned off!

The_Franz
Aug 8, 2003

-funroll-loops

it's got 'fun' right in the name!

akadajet
Sep 14, 2003

The_Franz posted:

-funroll-loops

it's got 'fun' right in the name!

certainly the silliest compiler flag

Soricidus
Oct 21, 2010
freedom-hating statist shill
-OooooOOOOooooOOOOOooo

rotor
Jun 11, 2001

classic case of pineapple derangement syndrome
i always laugh at -Wextra

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Dijkstracula posted:

well of course it is a language primitive, no more or less so than local goto keyword or signals or any other non-structured control flow mechanism that is part of the language

it’s not though, it’s part of the standard library

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

leper khan posted:

What other options do I have? I'd rather not write ASM and manually port to other architectures. And not all platforms I'm targeting have a C++ compiler.

sure they do, LLVM has a backend that can generate ANSI C89 so you can use clang++ as a glorified CFront

it may have bitrotted over the past decade though so you may need to do some forward-porting work first

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
as we all know, the c standard library is a well-designed and complete collection of functions which behave consistently across platforms, compilers, and libc implementations, so every c programmer can feel confident in making use of them

Adbot
ADBOT LOVES YOU

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

eschaton posted:

it’s not though, it’s part of the standard library

Why is this a distinction that matters? The language spec says what goes into the standard library, and setjmp is defined in it, so unless you really want to get nitpicky about "goto is a lexical token whereas setjmp is a macro that expands to something implementation-specific", as far as anyone actually cares they are both components of the language

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply