Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:23:59+00:00 2026-06-15T15:23:59+00:00

Working on a small embedded system, I wanted to experiment with something like C

  • 0

Working on a small embedded system, I wanted to experiment with something like C coroutines that you find implemented with switch/case/macro constructs and gcc’s labels as values extension. So I came up with some structures and functions and a pattern so that I could write functions like the following (just a test/example function):

void fiber1(FiberContext *fiber)
{
    if (fiber->restore) goto fiber->restore; // initial jump if called for
stateA:
    printf("Fiber 1: A state\n");
    fiber->misc = &&stateB;
    fiber->restore = &&sleep;
    return;
stateB:
    printf("Fiber 1: A state\n");
    fiber->misc = &&stateA;
    fiber->restore = &&sleep;
    return;
sleep:
    fiberSleepTicks(fiber, 1000000);
    fiber->restore = fiber->misc ? fiber->misc : &&stateA;
    return;
}

However GCC does not like the original goto fiber->restore (restore is a void* member of a FiberContext). My thought had been that basically, I would capture the label to jump to when I returned in an external structure, leave the function, and then come back and jump to the new label.

I think, what I’ve concluded is that GCC doesn’t know how to do that, because the && operator produces an absolute jump address, not one that is relative to the current function stack. So I wouldn’t be able to safely reuse it, because there’s nothing to say I wouldn’t call this function with different stack depths.

So my question is twofold basically. Am I right in my understanding in why it won’t work/compile? OR is it something else, and if so, what am I doing wrong with this feature? I’m compiling with just gcc -std=gnu99.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:23:59+00:00Added an answer on June 15, 2026 at 3:23 pm

    Try

    goto *(fiber->restore);
    

    See

    http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

    Also, the stack depth does not matter for the function code address – only shared library relocations do (the page above also explains how to do that nicely).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a simple protocol stack for a small embedded system (multidrop,
I am working on small scale deployment system for our in-house software that manages
Iam working on small booking room system. In my solution I have a Reservation
Im working on a small application to try out an idea that I have.
I'm working on a small app that uses the Facebook API. What I want
I'm trying to set up a small working sample of Hibernate that I found
and greetings to all members. I'm working on a small embedded data acquisition hardware
I'm working on an embedded Linux project that interfaces an ARM9 to a hardware
We have service that's working with small to large sets of data (document generation),
I am working on an embedded system running Linux on a DSP. Now we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.