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

  • Home
  • SEARCH
  • 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 8041049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:05:22+00:00 2026-06-05T04:05:22+00:00

This c code crash with a segmentation fault if I compile with GCC using

  • 0

This c code crash with a segmentation fault if I compile with GCC using -fomit-frame-pointer and -mrtd.

Is my code wrong in some way? Other function pointers works as expected, but not when its the free-function that is being passed? I get a warning when compiling, but I dont understand why or what I should do to fix. (I usually dont code in c, this error comes from a 3d part library that I use)

I need rtd/stdcall because Im on windows and need to call this library from python with ctypes, and -fomit-frame-pointer is included by default when compiling with GCC with -O1. (GCC version is 4.6.1 from TDM/Mingw32) It feels a bit strange that a default optimization option would cause trouble?

c-code:

#include <stdlib.h>

// void free ( void * ptr );
void test(void* o, void (*freeFunc)(void*)) {
    freeFunc(o);
}

int main() {
    int *p = (int *)calloc(1, sizeof(int));
    test(p, free);
}

compiled with:

gcc -fomit-frame-pointer -mrtd -c fx.c
gcc -fomit-frame-pointer -mrtd fx.o -o fx.exe

compile warning:

fx.c: In function 'main':
fx.c:11:5: warning: passing argument 2 of 'test' from incompatible pointer type[enabled by default]
fx.c:5:6: note: expected 'void (*)(void *)' but argument is of type 'void (*)(void *)'
  • 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-05T04:05:24+00:00Added an answer on June 5, 2026 at 4:05 am

    From the GCC manual page for -mrtd:

    Warning: this calling convention is incompatible with the one
    normally used on Unix, so you cannot use it if you need to call
    libraries compiled with the Unix compiler.
    

    The warning is kind of bizarre, but I believe it’s simply trying to tell you that you’re passing a pointer to a function which uses an incompatible calling convention. I imagine the free in libc would be such a function; I’m surprised that calling calloc works at all. (Or perhaps it isn’t, and what you’re seeing is a delayed failure!)

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

Sidebar

Related Questions

why does this code crash? is using strcat illegal on character pointers? #include <stdio.h>
Sometimes we put some debug prints in our code this way printf(successfully reached at
The Problem I'm receiving crash reports from users that look like this: Code Type:
This code works some of the time, but then sometimes crashes with a EXC_BAD_ACCESS
Possible Duplicate: C programming, why does this large array declaration produce a segmentation fault?
Why does this code crash? CustomDatabaseHelper.java: public class CustomDatabaseHelper { SQLiteDatabase db; private static
This code causes my app to crash on an iPhone 4 and on the
If i run this code the application will crash, and i dont understand why,
i am using this code to insert names to table,i have a problem that
Possible Duplicates: Why does simple C code receive segmentation fault? Modifying C string constants?

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.