Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #82653
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Can extern "C" functions throw exceptions |
| Date | 2021-12-16 04:21 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <86mtl04u6m.fsf@linuxsc.com> (permalink) |
| References | (5 earlier) <shmflb$74h$4@dont-email.me> <86a6jlrjyd.fsf@linuxsc.com> <9106335c-2f48-4735-8c69-2b829fc450ccn@googlegroups.com> <868rwm6adq.fsf@linuxsc.com> <4fcuJ.86590$QB1.25353@fx42.iad> |
Richard Damon <Richard@Damon-Family.org> writes: > On 12/14/21 6:21 PM, Tim Rentsch wrote: > >> "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> writes: >> >>> On Wednesday, October 6, 2021 at 4:12:52 PM UTC-4, Tim Rentsch wrote: >>> >>>> James Kuyper <james...@alumni.caltech.edu> writes: >>>> >>>>> On 9/12/21 9:44 AM, Chris Vine wrote: >>> >>> ... >>> >>>>>> For functions, it does more than affecting naming. The language >>>>>> linkage of a function determines two things: the function's name >>>>>> (name mangling) and the function's type (calling convention). >>>>> >>>>> Furthermore, and not widely appreciated, those two aspects are >>>>> separable by using a typedef for a function's type. The language >>>>> linkage of the typedef determines the calling convention, while >>>>> the language linkage of the function itself determines the name >>>>> mangling. >>>> >>>> Can you illustrate how that would be done? Since the language >>>> linkage of a function is part of its type, it sounds like trying >>>> to do such a thing would inevitably lead to undefined behavior. >>> >>> The language linkage of a function's type is indeed part of that >>> type. The language linkage of a function's name is not. The >>> standard's description of language linkage in 9.11p1 starts with >>> the sentence "All function types, function names with external >>> linkage, and variable names with external linkage have a language >>> linkage.", clearly making the point that the language linkage of a >>> function's type is a distinct thing from the language linkage of a >>> function's name. The standard could have inextricably linked them >>> together - but it does not. In fact, 9.11p5 includes an example >>> demonstrating how they can be separated: >>> >>> extern "C" typedef void FUNC(); >>> FUNC f2; // the name f2 has C ++ language linkage and the >>> // function?s type has C language linkage >>> >>> [...] >> >> Thank you for this citation. It doesn't answer all my questions >> but it certainly does provide an illuminating example. >> >> It appears, however, that in practice there is no difference >> between a type with a C language linkage and a C++ language >> linkage. Apparently most compilers ignore the distinction >> because following the rules would break too much code. Here >> is a link to stackoverflow with more information: >> >> https://stackoverflow.com/questions/26647259/ >> is-extern-c-a-part-of-the-type-of-a-function > > Maybe a better way of saying that is most platform ABIs don't allow > for a difference, because it would break too much existing code. If the compiler had been doing its job all along then it wouldn't break any code. The whole point of having language linkage be part of the type is to accommodate different ABIs for the two languages, without having to worry about using the wrong one because any violations would be caught by the type checker. Furthermore, even if the ABIs are the same, the language standard requires a diagnostic, so any C++ implementation should at least give a warning. If I give a -pedantic option then I expect (wrongly it seems) that all language rules will be faithfully observed. Apparently -pedantic means "we're going to follow all the rules that we think are worth following." And to the best of my knowledge clang is no better than gcc in this respect. Very disappointing.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can extern "C" functions throw exceptions Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-11 12:35 +0200
Re: Can extern "C" functions throw exceptions Bo Persson <bo@bo-persson.se> - 2021-09-11 13:49 +0200
Re: Can extern "C" functions throw exceptions "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-11 13:57 +0200
Re: Can extern "C" functions throw exceptions Paavo Helde <myfirstname@osa.pri.ee> - 2021-09-11 15:19 +0300
Re: Can extern "C" functions throw exceptions Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-11 15:32 +0200
Re: Can extern "C" functions throw exceptions HorseyWorsey@the_stables.com - 2021-09-11 15:54 +0000
Re: Can extern "C" functions throw exceptions "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-11 13:55 +0200
Re: Can extern "C" functions throw exceptions Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-11 15:34 +0200
Re: Can extern "C" functions throw exceptions Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-11 15:58 +0200
Re: Can extern "C" functions throw exceptions "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-09-11 17:00 +0200
Re: Can extern "C" functions throw exceptions "daniel...@gmail.com" <danielaparker@gmail.com> - 2021-10-06 13:36 -0700
Re: Can extern "C" functions throw exceptions Branimir Maksimovic <branimir.maksimovic@icloud.com> - 2021-10-06 20:42 +0000
Re: Can extern "C" functions throw exceptions Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-06 16:12 -0700
Re: Can extern "C" functions throw exceptions Branimir Maksimovic <branimir.maksimovic@icloud.com> - 2021-10-06 23:22 +0000
Re: Can extern "C" functions throw exceptions Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-06 17:03 -0700
Re: Can extern "C" functions throw exceptions HorseyWorsey@the_stables.com - 2021-09-11 15:56 +0000
Re: Can extern "C" functions throw exceptions David Brown <david.brown@hesbynett.no> - 2021-09-11 20:10 +0200
Re: Can extern "C" functions throw exceptions Juha Nieminen <nospam@thanks.invalid> - 2021-09-12 09:20 +0000
Re: Can extern "C" functions throw exceptions Paavo Helde <myfirstname@osa.pri.ee> - 2021-09-12 12:34 +0300
Re: Can extern "C" functions throw exceptions David Brown <david.brown@hesbynett.no> - 2021-09-12 12:24 +0200
Re: Can extern "C" functions throw exceptions Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-12 12:29 +0200
Re: Can extern "C" functions throw exceptions Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-09-12 14:44 +0100
Re: Can extern "C" functions throw exceptions James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-12 23:13 -0400
Re: Can extern "C" functions throw exceptions David Brown <david.brown@hesbynett.no> - 2021-09-13 09:30 +0200
Re: Can extern "C" functions throw exceptions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-06 13:12 -0700
Re: Can extern "C" functions throw exceptions "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2021-10-07 07:09 -0700
Re: Can extern "C" functions throw exceptions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-14 15:21 -0800
Re: Can extern "C" functions throw exceptions Richard Damon <Richard@Damon-Family.org> - 2021-12-14 21:17 -0500
Re: Can extern "C" functions throw exceptions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-16 04:21 -0800
Re: Can extern "C" functions throw exceptions "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2021-12-14 19:06 -0800
Re: Can extern "C" functions throw exceptions Ian Collins <ian-news@hotmail.com> - 2021-12-16 13:14 +1300
Re: Can extern "C" functions throw exceptions "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-12-15 18:05 -0800
Re: Can extern "C" functions throw exceptions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-16 04:37 -0800
Re: Can extern "C" functions throw exceptions Ian Collins <ian-news@hotmail.com> - 2021-12-17 09:39 +1300
Re: Can extern "C" functions throw exceptions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-16 19:24 -0800
Re: Can extern "C" functions throw exceptions Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-16 04:29 -0800
Re: Can extern "C" functions throw exceptions Juha Nieminen <nospam@thanks.invalid> - 2021-09-13 05:34 +0000
Re: Can extern "C" functions throw exceptions Paavo Helde <myfirstname@osa.pri.ee> - 2021-09-13 09:55 +0300
Re: Can extern "C" functions throw exceptions Paavo Helde <myfirstname@osa.pri.ee> - 2021-09-11 15:12 +0300
Re: Can extern "C" functions throw exceptions red floyd <no.spam.here@its.invalid> - 2021-09-13 13:21 -0700
csiph-web