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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:08:39+00:00 2026-05-27T18:08:39+00:00

Code snippets from two C source files: A.c Channel *testChannelGet() { Channel *ch =

  • 0

Code snippets from two C source files:

A.c

Channel *testChannelGet()
{
    Channel *ch = channelGet (parser,parserCh);
    return ch;
}

B.c

Channel *channelGet(UINT8 parser, UINT16 parserCh)
{
    chnl.player = &solPlayer;
    return((Channel *)&chnl);
}

I compile both files and create a static and a shared library. Now I call testChannelGet from a sample program. When I link it against the static library, it works perfectly. But if I link it against the shared library, its SEGFAULTing. Debugging tells me that the pointer returned from channelGet is changing the moment it returns. GDB output below.

174         Channel *ch = channelGet (parser,parserCh);
(gdb) s
channelGet (parser=1 '\001', parserCh=1) at B.c:15174
15174           chnl.player = &solPlayer;
(gdb) n
15175           return((Channel *)&chnl);
(gdb) p ((Channel *)&chnl)
$1 = (Channel *) 0x7ffff7fed1a0
(gdb) n
15176   }
(gdb) n
testChannelGet at A.c:175
175         return ch;
(gdb) p ch
$2 = (Channel *) 0xfffffffff7fed1a0

It seems the address value points to a different offset now – 0xfffffffff7fed1a0 vs 0x7ffff7fed1a0 . The last bytes in both addresses are the same.

Any hints? I have tried the -fPIC option to no avail.

  • 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-05-27T18:08:41+00:00Added an answer on May 27, 2026 at 6:08 pm

    Is there a prototype in scope for channelGet() in A.c?

    If not, the results you’re seeing could be explained as follows:

    • channelGet() is assumed to return int (due to lack of prototype), so the result is truncated to 0xf7fed1a0
    • then it is cast to a 64-bit pointer, so gets sign-extended to 0xfffffffff7fed1a0

    (You should get complaints about this if you compile with warnings enabled, of course…)

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

Sidebar

Related Questions

I need to isolate user-written code snippets from each other in javascript. For now
Help me please to find out what's the difference between these two code snippets:
Given the following code snippet from inside a method; NSBezierPath * tempPath = [NSBezierPath
This is a code snippet from O'Reilly Learning Opencv, cvNamedWindow(Example3, CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture(argv[1]);
This code snippet is from C# in Depth static bool AreReferencesEqual<T>(T first, T second)
The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk
code snippet: //byte[] myByteArray = byte array from database (database BLOB) myByteArray = (byte[])
I have the following snippet from my code: switch ($extention) { case gif: $src
I need a short code snippet to get a directory listing from an HTTP
In the code snippet below, from my jQuery setup, I need to check if

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.