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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:04:50+00:00 2026-06-03T14:04:50+00:00

The code comes from this page: http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html Can you help me understand this? It

  • 0

The code comes from this page: http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html

Can you help me understand this?
It takes the address of the function pointer, casts it to void** and then dereferences it. I don’t know why it has to work like this.

I appreciate your help! Until now, the only advice I have gotten was “read it from right to left” or something like “read it in cycles from right to left”.

  • 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-03T14:04:51+00:00Added an answer on June 3, 2026 at 2:04 pm

    The meaning of the code is:

    1. Take the address of fptr. The type of this expression is pointer-to-pointer-to-function (of some specific type).
    2. Cast that pointer expression to “pointer to pointer to void”.
    3. Dereference that pointer to access the object fptr as if it were an object of type void *.
    4. Assign the result of the right to the lvalue obtained in step 3.

    Unfortunately, whoever wrote this example in POSIX was on crack, because step 3 violates the aliasing rules of the C language and thus invokes undefined behavior. In particular, real-world compilers will optimize this code in ways that breaks the intended usage.

    What the author of this example was trying to achieve was avoiding casting the right-hand side from pointer to void to pointer to function. This is based on a claim that the C standard requires this cast to generate a warning, but I have searched thoroughly for such a requirement and can find no such requirement.

    If such a problem really does exist (the warning requirement), then the only way to silence the warning without invoking undefined behavior (like the bad example in the text of POSIX) is to do this:

    void (*fptr)(); // or whatever function pointer type you want
    void *temp = dlsym(handle, "my_function");
    memcpy(&fptr, &temp, sizeof fptr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code comes from: http://code.activestate.com/recipes/577090-file-encryption-using-stream-cipher/ import sys import random if len(sys.argv) != 4: print
This example is taken from the Linux System Programming book, page 88. Code: http://pastebin.com/mEfmHbPP
This code comes from a tutorial so it's not originally my own work. What
I am trying to understand this inline assembly code which comes from _hypercall0 here
Note: This code actually codes from a tutorial book I'm reading at the moment,
I have old code that uses size_t which IIRC comes from cstring.h. On OS
Currently, the following code shows a blank line if Address2 (which comes from the
I have a database that uses codes. Each code can be anywhere from two
I'm looking to pass a keyword from a HTML page to a PHP page
this is basically what I'm doing. I select a science article from en.wikipedia.org and

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.