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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:36:44+00:00 2026-05-30T16:36:44+00:00

Recently I’ve been wrapping a lot of C++ code in python, and I find

  • 0

Recently I’ve been wrapping a lot of C++ code in python, and I find this block (taken directly from the python documentation) a bit troubling:

static PyMethodDef keywdarg_methods[] = {
/* The cast of the function is necessary since PyCFunction values
 * only take two PyObject* parameters, and keywdarg_parrot() takes
 * three.
 */
{"parrot", (PyCFunction)keywdarg_parrot, METH_VARARGS | METH_KEYWORDS,
 "Print a lovely skit to standard output."},
{NULL, NULL, 0, NULL}   /* sentinel */
};

The issue is the line which casts kwarg_parrot, of type PyCFunctionWithKeywords to a PyCFunction.

Coming from a C++ background (and given that I am wrapping C++ code), it seems wrong to use a C-style cast. I’ve tried static_cast, and dynamic_cast, both of which cause the compiler to complain (with good reason, this really is an unsafe cast in the general sense). The only viable C++ option seems to bereinterpret_cast, but so far as I can tell this is a more verbose version of a C-style cast.

Granted, the above is wrapped in an extern "C" block, so maybe the C way is the correct way. Does anyone have any better ideas? (What I’d really like to see would be a solution that could automatically generate the doc string based on the keywords.)

Unfortunately, solutions like Boost.Python and SWIG are off the table. (I’m working within an ugly framework)

  • 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-30T16:36:45+00:00Added an answer on May 30, 2026 at 4:36 pm

    Main Python implementation is written in C, not C++.

    Thus, libpython code that evaluates keywdarg_methods[] is written in C and calls keywdarg_parrot via C calling conventions.

    If you want C++ style integration with Python, find a way to use boost.python instead. Or perhaps cython.

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

Sidebar

Related Questions

Recently, we discovered odd behavior in some old code. This code has worked for
Recently I asked this question: Find Common Values in several arrays, or lists VB.NET
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
Recently our site has been deluged with the resurgence of the Asprox botnet SQL
Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Recently a friend and I were talking about securing stored procedure code in a
Recently I have been dealing with windows LogonUser API. The LogonUser api returns different
Recently I've begun to code in Objective-C for iOS 5 devices. My brand new
Recently we have released our product. Our team decided to preserve the source code

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.