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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:06:04+00:00 2026-06-04T19:06:04+00:00

I’m working on assignment for an operating systems class. We are given code to

  • 0

I’m working on assignment for an operating systems class. We are given code to use to help us with our assignment, but I have little programming experience with C, and I can’t figure out how to use it. What I’m trying to do is print the information at the head of the list. The list is a list of structs defined as

typedef struct 
{
    char name[NAME_MAX];
    int  lifetime;
} pcb_t;

int 
List_head_info ( List_t *list, void **data )
{
     int all_ok = 0;

     *data = NULL;
     if ((list != NULL) && (list->head != NULL)) {
         *data = list->head->data;
         all_ok = 1;
     }

     return all_ok;
}

I tried to display them with:

printf("test: %s", List_head_info(&processes, (void *)pcb)->name);

but I am given the error invalid type argument a->a when compiling.

  • 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-04T19:06:05+00:00Added an answer on June 4, 2026 at 7:06 pm

    When you call List_head_info(), you will get back two things:

    1. A pointer (void *) to the head data, or NULL.
    2. A status indicating whether the pointer is non-NULL.

    If it returns successfully, you can convert (coerce, or cast) the void * to a pcb_t * and then use that to print the data.


    How would I do that specifically?

    Probably something a bit like this:

    List_t list;
    
    ...code to initialize and maybe add things to the list...
    
    void *head_data = 0;
    if (List_head_info(&list, &head_data))
    {
        pcb_t *item = (pcb_t *)head_data;
        printf("Lifetime: %.2d; Name: %s\n", item->lifetime, item->name);
    }
    

    Strictly, the initialization of head_data is superfluous; the code in List_head_info() always sets the value at least once (to NULL or 0) and sometimes twice (the second time to the data component of the head item on the list).

    This is ‘example code’ with enough information in it to compile. I’ve ‘reverse engineered’ the list structures enough to make sense; the actual implementation will be different, of course. This compiles cleanly under fairly stringent GCC warning levels, with GCC 4.1.2 and 4.7.0 on Mac OS X 10.7.4. AFAICS, it avoids some complex issues related to ‘strict aliasing’ which you really don’t want to have to worry about at this stage.

    #include <stdio.h>
    
    enum { NAME_MAX = 40 };
    
    typedef struct Node Node;
    struct Node
    {
        void *data;
        Node *next;
    };
    
    typedef struct
    {
        Node *head;
        Node *tail;
    } List_t;
    
    typedef struct 
    {
        char name[NAME_MAX];
        int  lifetime;
    } pcb_t;
    
    extern int List_head_info(List_t *list, void **data);
    extern void another_func(List_t processes);
    
    void another_func(List_t list)
    {
        void *head_data = 0;
        if (List_head_info(&list, &head_data))
        {
            pcb_t *item = (pcb_t *)head_data;
            printf("Lifetime: %.2d; Name: %s\n", item->lifetime, item->name);
        }
    }
    
    int 
    List_head_info ( List_t *list, void **data )
    {
        int all_ok = 0;
    
        *data = NULL;
        if ((list != NULL) && (list->head != NULL)) {
            *data = list->head->data;
            all_ok = 1;
        }
    
        return all_ok;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Thanks in advance for your help. I have a need within an application to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

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.