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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:43:01+00:00 2026-06-09T18:43:01+00:00

I came across this line of code today in process and thread chapter of

  • 0

I came across this line of code today in process and thread chapter of C programming book:

printf("[Child]  child thread id: 0x%x\n", (unsigned int)pthread_self());

I’ve never seen the part (unsigned int)pthread_self(), I don’t know what the first pair of parenthesises is used for. Any idea?

p.s:

I remember that in the documentation of php, there’s similar expression for function documentation:

int time()

but in actual code, we only use the part time(), int is for documentation purpose to show the return value of function time()


Update:

I type the example code in the book that test the each thread id:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>

int global = 5;

void* ChildCode(void* arg) {
    int local = 10;

    global++;
    local++; 
    printf("[Child]  child thread id: 0x%x\n", (unsigned int)pthread_self());
    printf("[Child]  global: %d  local: %d\n", global, local);

    pthread_exit(NULL);
}

int main() {
  pthread_t  childPid;
  int       local = 10;

    printf("[At start]  global: %d  local: %d\n", global, local);

  /* create a child thread */
  if (pthread_create (&childPid, NULL, ChildCode, NULL) != 0)
  {
    perror("create");
    exit(1);
  } else { /* parent code */
    global++;
    local--; 
    printf("[Parent] parent main thread id : 0x%x\n", (unsigned int)pthread_self());
    printf("[Parent] global: %d  local: %d\n", global, local);
    sleep(1);
  }
  printf("[At end] global: %d  local: %d\n", global, local);
  exit(0);
}

and it gives me some note(not warning not error):

clang example_thread.c 
/tmp/example_thread-9lEP70.o: In function `main':
example_thread.c:(.text+0xcc): undefined reference to `pthread_create'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I’ve no idea with the code, any idea?

  • 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-09T18:43:03+00:00Added an answer on June 9, 2026 at 6:43 pm

    The parentheses are casting the return value of pthread_self to unsigned int. pthread_self returns pthread_t, which is an unspecified arithmetic type that is not appropriate for use with printf.

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

Sidebar

Related Questions

I'm reading Stroustrup's Programming: Principles and Practice and came across this code: int main()
In my parallel programming book, I came across this code that says the slaves
I came across this line in a book on WCF: ...and the languages used
I came across this line of code in an application I am revising: substr($sometext1
I came across a line of code using Python's numpy that looked like this:
I was looking at some code and I came across this line: Machine drink[]
I came across some code today that looks like this: subroutine sub(hello,world,this,routine,takes,a, & &
I came across this line of code: if( -f <filename> ) { ... }
I came across this line in some code and can't find the syntax defined
I was just browsing Sizzle's source code and I came across this line of

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.