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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:37:02+00:00 2026-06-12T17:37:02+00:00

I have a doubt about a syntax used in linux kernel code. I have

  • 0

I have a doubt about a syntax used in linux kernel code. I have an intuition of what it does but I want to know it more formally. I am using kernel v3.5.4

In file /include/linux/sched.h the following is defined

struct task_struct {
    volatile long state;
    //some more data members
};

and in file /include/linux/init_task.h file the following is defined:

#define INIT_TASK(tsk) {
    .state     = 0,               \
    //some more initializations

}

I am confused about two things:

a) I feel it is used for initialization but can anyone suggest some good read for this type of initialization for structures.

b) I do not understand how the following initialization works. Like how this #define and the corresponding task_struct structure are related.

[EDIT]
I noticed the following things also:
c) Is \ at the end of every line necessary.

d) There are many parts of kernel doe wrapped in #ifdef #endif. If you want to initialize a data member wrapped in #ifdef #endif can we use this form of initialization. I mean can we use #ifdef #endif inside INIT_TASK() like this

#define INIT_TASK(tsk) {
    .state     = 0,               \

    //some more initializations
    #ifdef CX 
    .tickets   = 5,               \
    #endif

}
  • 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-12T17:37:03+00:00Added an answer on June 12, 2026 at 5:37 pm
    struct task_struct whatever = INIT_TASK(someTsk);
    

    This results in the following code:

    struct task_struct whatever = { .state = 0 };
    

    which is valid C syntax to initialize fields in a struct via their name instead of their position. Doing so makes the code safe against struct members that are not added at the last position.

    Regarding the backslashes: Yes, they are necessary so the preprocessor knows that the macro continues on the next line.

    No, you cannot use #ifdef inside a macro.

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

Sidebar

Related Questions

I have a small architecture doubt about organizing code in separate functional units (most
I have doubt about this two pattern, like MVC and PAC, which is more
I have little doubt about adapter class. I know what's the goal of adapter
I have a doubt about if that approach is possible, lets say you want
I have some doubt about the title, but I couldn't come up with anything
I have a doubt about mutexes. Global mutex; /// more things Acquire lock on
I'm using socket.io. It works well, but I have a short doubt about the
This is the text field delegate method but i have doubt about return type
I am creating a http client cache, but I have a doubt about the
I have a doubt about Model behavior in Spring MVC. I have a controller

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.