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 8058819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:28:06+00:00 2026-06-05T09:28:06+00:00

I am an electronics guy so, treat me well, please. I was reading this

  • 0

I am an electronics guy so, treat me well, please.

I was reading this article about real time operating systems for 8-bit microcontrollers. I came across this function with a weird looking argument. I could not understand what it is doing. I know that void means “no type”. I am guessing that (*Task) is the casting. I really have no idea what those brackets do after that.

What does this function’s argument include?

Also, I couldn’t understand what does *(int*)((NewTCB->Stack) + (STACK_DEPTH-2)) = (int)Task; do?

enter image description here

  • 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-05T09:28:08+00:00Added an answer on June 5, 2026 at 9:28 am

    void (*Task)() is actually a function pointer. Basically it is saying: “the parameter name is Task and it is a function which returns void and (since this is c not c++) takes any number of arguments.

    So you could call it like this:

    void my_task() {
        /* do something */
    }
    
    TaskCreate(my_task);
    

    Of course, it would also be safe to write void my_task(void) { as well. When coding c, I personally prefer to explicitly say “there are no parameters”

    Finally, *(int*)((NewTCB->Stack) + (STACK_DEPTH-2)) = (int)Task; is doing some casting magic.

    Let’s disect it:

    (int)Task is first converting Task to an int (which is questionable, but probably ok for your particular architecture/OS. Personally, I would use a long to be safe).

    ((NewTCB->Stack) + (STACK_DEPTH-2)) is just doing some simple arithmetic on NewTCB->Stack to get a pointer to a location in the TCB‘s stack.

    *(int*) says “convert this to an int * and then deference (read or write) the location it points to.

    We could write this more simply as follows:

    int f = (int)Task;
    int s = ((NewTCB->Stack) + (STACK_DEPTH-2)); /* I don't know the type of `NewTCB->Stack`, so we'll pretend 'int' for now */
    int *stack_ptr = (int*)s;
    *stack_ptr = f;
    

    which is probably more clear.

    FOLLOW UP: I’d like to point out how I use tend to use function pointers since the syntax can be a bit confusing sometimes. And I find this approach to be very helpful. Basically I like to create a typedef for the function pointer and use that instead, I find it a lot easier to get right:

    For example:

    /* typedef func_t to be a pointer to a function taking no arguments and returning void */
    typedef void (*func_t)(void); 
    

    Then later…

    void CreateTask(func_t task) {
        /* same work as your example, just a little easier to read */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know very well about RAM and HDD architecture, or how electronics deals
I'm reading this article and on the part with the query: SELECT node.name FROM
I don't know lots of things about the electronics field and controllers. But I
I have php array like this: Array ( [0] => Array ([electronics] => TV
I'm trying to make canvas draw code for the purposes of electronics education. Please
I am a student with a mainly electronics background getting into programing. The more
I have 2 categories in my magento website ie Books and Electronics. I want
I'm trying to make a truth-table generator for a digital electronics course because that's
How do I transform www.bestbuy.com/site/Electronics\Audio\abcat0200000.c=3fid=3dabcat0200000 into its original format? www.bestbuy.com/site/Electronics/Audio/abcat0200000.c?id=abcat0200000 Is there a urldecode
I have a hierarchical data that goes like this: +----------------------+-------+ | name | depth

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.