call c++ function from c

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Collins

    #16
    Re: call c++ function from c

    CBFalconer wrote:
    Chris Torek wrote:
    >CBFalconer <cbfalconer@mai neline.netwrote :
    >>
    >>[Using C++'s extern "C" construct] enables C++ to call C, not
    >>the reverse direction.
    >Actually, it works both ways, provided some reasonably obvious
    >and straightforward restrictions are met.
    >>
    >(It is possible to write C++ code that can*not* call C code, nor
    >vice versa; and mixing one vendor's C compiler with another's C++
    >compiler can result in various disasters, but this is equally true
    >for mixing one vendor's C compiler with another vendor's C compiler.
    >But if the calls can be done at all, the C++ extern "C" method is
    >almost always the way to go. Further discussion about this really
    >belongs in comp.lang.c++ and/or vendor-specific newsgroups, of
    >course.)
    >
    The C++ system attempts to adorn external calls with information
    about parameters, etc. in various ways. The C system has no way of
    understanding this mess. Thus C can't call C++ bcause the
    'adornments' are missing. However, C++ has a provision for
    dropping those 'adornments' to call precompiled C code.
    >
    I think you are completely missing the point about it working both ways,
    never mind.

    --
    Ian Collins.

    Comment

    • SM Ryan

      #17
      Re: call c++ function from c

      CBFalconer <cbfalconer@yah oo.comwrote:

      # understanding this mess. Thus C can't call C++ bcause the
      # 'adornments' are missing. However, C++ has a provision for

      That comes as a shock and disappointment to all of us who
      actually do this.

      --
      SM Ryan http://www.rawbw.com/~wyrmwif/
      If you plan to shoplift, let us know.
      Thanks

      Comment

      • Richard

        #18
        Re: call c++ function from c

        SM Ryan <wyrmwif@tang o-sierra-oscar-foxtrot-tango.fake.orgw rites:
        CBFalconer <cbfalconer@yah oo.comwrote:
        >
        # understanding this mess. Thus C can't call C++ bcause the
        # 'adornments' are missing. However, C++ has a provision for
        >
        That comes as a shock and disappointment to all of us who
        actually do this.

        Comment

        • Marcin Wolcendorf

          #19
          Re: call c++ function from c

          Hi Chris,



          Chris Torek <nospam@torek.n etwrote:
          Background: Marcin Wolcendorf provided a mostly-correct and suitably
          worded answer, to which I did not object. Then:
          >
          >
          ...snip..

          To make it short:
          - Please, if you add some criticism- be specific. I'd be happy if you
          pointed out mistakes I made. I guess this is what you object to do for
          philosophic reasons. Well, I have no solution to that, then; I need
          facts, not foggy clues and riddles anyway.
          - I can see your point of limiting the topics to 'C only'; I somewhat
          agree. Nevertheless making group too narrow will make it unusable
          (IMHO). Some other groups may do the same- then someone looking for
          answers will be bounced from every group with 'OT' excuse. IMO- this
          is the place to provide answers, not frustration. What's more- if
          you'll make it too strict, too narrow, you'll soon find there is
          no-one to talk to.


          Regards (and EOT),

          M.W.

          Comment

          • Richard Heathfield

            #20
            Re: call c++ function from c

            Marcin Wolcendorf said:

            <snip>
            - I can see your point of limiting the topics to 'C only'; I somewhat
            agree.
            Good.
            Nevertheless making group too narrow will make it unusable
            So will making it too wide. This newsgroup discusses C. That is a wide
            enough topic to ensure that this group has been useful for almost a
            quarter of a century.
            (IMHO). Some other groups may do the same- then someone looking for
            answers will be bounced from every group with 'OT' excuse. IMO- this
            is the place to provide answers, not frustration.
            Right - and the answer to your question is that C does not provide a
            mechanism to interface specifically with C++ functions. If you find the
            answer frustrating, that's unfortunate, but it happens to be the
            correct answer nonetheless.
            What's more- if
            you'll make it too strict, too narrow, you'll soon find there is
            no-one to talk to.
            And if you make it too wide, you'll soon find there's nowhere left to
            ask about C, because the S/N ratio will drop through the floor and the
            C experts will give up bothering with the group, so the only people
            left to answer your questions will be the guessers.

            --
            Richard Heathfield <http://www.cpax.org.uk >
            Email: -www. +rjh@
            Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
            "Usenet is a strange place" - dmr 29 July 1999

            Comment

            • Richard

              #21
              Re: call c++ function from c

              Richard Heathfield <rjh@see.sig.in validwrites:
              Marcin Wolcendorf said:
              >
              <snip>
              >
              >- I can see your point of limiting the topics to 'C only'; I somewhat
              > agree.
              >
              Good.
              >
              >Nevertheless making group too narrow will make it unusable
              >
              So will making it too wide. This newsgroup discusses C. That is a wide
              enough topic to ensure that this group has been useful for almost a
              quarter of a century.
              C and your lecturing on topicality you mean. There is FAR more noise in
              this NG with our posturing and others rushing in with their OT
              admonishments than there is from perceived "off topic" original
              posts. Grow up and ignore them.

              Comment

              • Kenny McCormack

                #22
                Re: call c++ function from c

                In article <2y3ayg7qde.fsf @homelinux.net> , Richard <rgrdev@gmail.c omwrote:
                ....
                >C and your lecturing on topicality you mean. There is FAR more noise in
                >this NG with our posturing and others rushing in with their OT
                >admonishment s than there is from perceived "off topic" original
                >posts. Grow up and ignore them.
                If it weren't for off-topics posts, we'd have no posts at all!

                (Gloom, despair, and agony on me...)

                Comment

                • Keith Thompson

                  #23
                  Re: call c++ function from c

                  Richard <rgrdev@gmail.c omwrites:
                  Richard Heathfield <rjh@see.sig.in validwrites:
                  >Marcin Wolcendorf said:
                  ><snip>
                  >>
                  >>- I can see your point of limiting the topics to 'C only'; I somewhat
                  >> agree.
                  >>
                  >Good.
                  >>
                  >>Nevertheles s making group too narrow will make it unusable
                  >>
                  >So will making it too wide. This newsgroup discusses C. That is a wide
                  >enough topic to ensure that this group has been useful for almost a
                  >quarter of a century.
                  >
                  C and your lecturing on topicality you mean. There is FAR more noise in
                  this NG with our posturing and others rushing in with their OT
                  admonishments than there is from perceived "off topic" original
                  posts. Grow up and ignore them.
                  A great deal of the noise in this group, and a majority of your own
                  contributions (no I haven't actually measured), consists of *you*
                  lecturing us about topicality.

                  Many, perhaps most, posts saying that something is off-topic are well
                  received by their targets, especially when such posts include a
                  redirection to a more appropriate forum.

                  In this particular thread, the original question is about calling a
                  C++ function from C. The simple fact is that C provides no mechanism
                  for doing this. But C++ does. There are questions about whether the
                  C++ mechanism supports both calling C++ from C and vice versa. We
                  could speculate at length here about those questions, with C
                  programmers who really don't know C++ very well guessing what C++
                  provides. Or the question could be redirected to comp.lang.c++, where
                  it can be answered quickly and definitively, probably with a simple
                  citation of the C++ FAQ.

                  It wasn't entirely unreasonable for the original poster to ask the
                  question here. It was entirely reasonable to redirect the OP to
                  comp.lang.c++. Going back over the history of this thread, the very
                  first response (from Jens Thoms Toerring) did exactly that. (Jens
                  also tried to answer the question in C++ terms, which IMHO was
                  unwise.) If we could have just left it at that, the OP would have
                  gotten his answer and we wouldn't be wasting our time arguing about
                  topicality.

                  You don't like us posting articles saying that C++ is off-topic?
                  "Grow up and ignore them."

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
                  "We must do something. This is something. Therefore, we must do this."
                  -- Antony Jay and Jonathan Lynn, "Yes Minister"

                  Comment

                  Working...