|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
C++ header filesGuys,
I got the message below as a support request. I am not a C++ guy, and I have never actually read the standard, so I'd like to get some feedback from people who use it regularly. This user is requesting that I add: #ifdef __cplusplus extern "C" { #endif .... #ifdef __cplusplus } #endif To the main C API header files for C++ users. ATLAS's present approach is: http://math-atlas.sourceforge.net/errata.html#CPPheaders For the user suggestion, I have several questions: (1) is the '__cplusplus' macro part of the C++ standard, or a gnu-specific extension? (2) Does the standard say what happens if you have nested extern "C" declarations? (3) What are people's feelings on this proposal? Thanks, Clint >From noreply@... Sun Jun 22 22:59:13 2008 Return-Path: <noreply@...> X-Original-To: whaley@... Delivered-To: whaley@... To: noreply@... From: "SourceForge.net" <noreply@...> Subject: [ math-atlas-Support Requests-2000447 ] Comment on FAQ "How about C++ header files for the C ..." Content-Type: text/plain; charset="UTF-8" X-SourceForge-Tracker-unixname: math-atlas X-SourceForge-Tracker-trackerid: 379483 X-SourceForge-Tracker-itemid: 2000447 X-SourceForge-Tracker-itemstatus: Open X-SourceForge-Tracker-itemassignee: nobody X-SourceForge-Tracker-itemupdate-reason: Tracker Item Submitted X-SourceForge-Tracker-itemupdate-username: Item Submitter Date: Mon, 23 Jun 2008 03:59:01 +0000 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on mail0.cs.utsa.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 Status: RO Support Requests item #2000447, was opened at 2008-06-23 03:59 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=379483&aid=2000447&group_id=23725 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Problems during install Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Nobody/Anonymous (nobody) Assigned to: Nobody/Anonymous (nobody) Summary: Comment on FAQ "How about C++ header files for the C ..." Initial Comment: Hello, I installed ATLAS to do some comparisons with Intel MKL, AMD ACML etc. The test code is C++ and I am testing on FreeBSD 7.0. I ran into the problem of linking which is covered in the errata entry "How about C++ header files for the C interfaces?" I found this after I had worked out the problem (and yes I did read the docs - just missed this one as explained below). A couple of comments: 1. The error occurs at link time but the errata entry does not mention the link symptoms. If you are an expert C++ programmer then maybe it is obvious but for others I think that a note about the symptoms would be useful (esp when searching for symptoms on the web). 2. At the bottom of the entry it says "If you are a C++ programmer using ATLAS, and think differently, let me know." Well I am not a C++ programmer but I cannot see why the 'extern (C)' cannot be added to the cblas.h header file with appropriate ifdefs e.g. #ifdef __cplusplus extern "C" { #endif ... <the rest of cblas.h file> ... #ifdef __cplusplus } #endif This way it is no-op for C programs and will work without C++ programmers having to add noise to their code. It is also used in standard system files 'grep 'extern "C"' /usr/include/*.h' 3. As for the "Since ATLAS does not provide full OO C++ interfaces, I am reluctant to raise the expectation that it does by providing C++ specific header files." If the above ifdefs were added I do not believe it will raise expectations. Since it is an explicit 'extern "C"' you know they are C only interfaces. 4. Of course if you do add the 'extern "C"' as to the cblas.h file as suggested, existing code would have additional enclosing 'extern "C"'. I did a quick test and this does not appear to cause any problems. I have not used ATLAS enough to comment fully on its usefulness but it does appear to be extremely useful well written software. (I did read the ATLAS FAQ ;-) thanks -- tony maher tonymaher@... ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=379483&aid=2000447&group_id=23725 ************************************************************************** ** R. Clint Whaley, PhD ** Assist Prof, UTSA ** www.cs.utsa.edu/~whaley ** ************************************************************************** ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Math-atlas-devel mailing list Math-atlas-devel@... https://lists.sourceforge.net/lists/listinfo/math-atlas-devel |
|
|
Re: C++ header filesClint> I got the message below as a support request. I am not a C++ Clint> guy, and I have never actually read the standard, so I'd like to Clint> get some feedback from people who use it regularly. This user is Clint> requesting that I add: Clint> #ifdef __cplusplus Clint> extern "C" Clint> { Clint> #endif Clint> .... Clint> #ifdef __cplusplus Clint> } Clint> #endif That is the standard idiom. It will instruct the C++ compiler to not mangle the names between the braces (C linkage). C compilers will not see it. -- Skip Montanaro - skip@... - http://www.webfast.com/~skip/ "Be different, express yourself like everyone else." ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Math-atlas-devel mailing list Math-atlas-devel@... https://lists.sourceforge.net/lists/listinfo/math-atlas-devel |
|
|
Re: C++ header filesOn Tue, Jun 24, 2008 at 05:50:10PM -0500, skip@... wrote:
> Clint> #ifdef __cplusplus > Clint> extern "C" > Clint> { > Clint> #endif > Clint> .... > That is the standard idiom. It will instruct the C++ compiler to not mangle > the names between the braces (C linkage). C compilers will not see it. This is probably the wrong forum, but I've never understood why that was considered to be the appropriate strategy. Why should C code have a bunch of spurious C++-related fluff added? Surely the correct approach is for C++ code to wrap C includes in extern "C", as the syntax would seem to indicate? Every other language that has some way of linking to C code (and most do) has to do its own compatability shimming, with it's own foreign-function interface. My guess is that the process started when it was assumed that C++ was the future of C, and eventually everything would just be C++. That is much less clearly the case, now, IMO. Cheers, -- Andrew ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Math-atlas-devel mailing list Math-atlas-devel@... https://lists.sourceforge.net/lists/listinfo/math-atlas-devel |
|
|
Re: C++ header filesAndrew> This is probably the wrong forum, but I've never understood why Andrew> that was considered to be the appropriate strategy. Why should Andrew> C code have a bunch of spurious C++-related fluff added? Surely Andrew> the correct approach is for C++ code to wrap C includes in Andrew> extern "C", as the syntax would seem to indicate? I think it's mostly because C++ is used to compile C code. I know the Python source code uses this technique. I believe you can compile it with g++. Andrew> My guess is that the process started when it was assumed that Andrew> C++ was the future of C, and eventually everything would just be Andrew> C++. That is much less clearly the case, now, IMO. Thankfully. :-) -- Skip Montanaro - skip@... - http://www.webfast.com/~skip/ "Be different, express yourself like everyone else." ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Math-atlas-devel mailing list Math-atlas-devel@... https://lists.sourceforge.net/lists/listinfo/math-atlas-devel |
|
|
Re: C++ header filesThe __cplusplus macro is part of the ISO C++ standard, defined
precisely because the standards committee knew (presumably) that there would be people who would want to use their old plain C stuff. Similarly, ISO C has the macro __STDC__ defined. See here: http://docs.sun.com/app/docs/doc/819-5267/bkaep?a=view So, it is more than just idiom. It's required of a standards-compliant compiler. Cheers, Dave On Tue, Jun 24, 2008 at 7:13 PM, Andrew Reilly <andrew-atlas@...> wrote: > On Tue, Jun 24, 2008 at 05:50:10PM -0500, skip@... wrote: >> Clint> #ifdef __cplusplus >> Clint> extern "C" >> Clint> { >> Clint> #endif >> Clint> .... > >> That is the standard idiom. It will instruct the C++ compiler to not mangle >> the names between the braces (C linkage). C compilers will not see it. > > This is probably the wrong forum, but I've never understood why > that was considered to be the appropriate strategy. Why should > C code have a bunch of spurious C++-related fluff added? Surely > the correct approach is for C++ code to wrap C includes in > extern "C", as the syntax would seem to indicate? > > Every other language that has some way of linking to C code (and > most do) has to do its own compatability shimming, with it's own > foreign-function interface. > > My guess is that the process started when it was assumed that > C++ was the future of C, and eventually everything would just be > C++. That is much less clearly the case, now, IMO. > > Cheers, > > -- > Andrew > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > Math-atlas-devel mailing list > Math-atlas-devel@... > https://lists.sourceforge.net/lists/listinfo/math-atlas-devel > -- Email: david.w.h.chin AT gmail.com dwchin AT lroc.harvard.edu http://gallatin.physics.lsa.umich.edu/~dwchin/Work Public key: http://david.w.h.chin.googlepages.com/crypto.html pub 1024D/553CB7B8 2007-08-07 [expires: 2008-08-06] Key fingerprint = 0AD6 6DDC 204D AA4A 8957 52D1 0D93 C52A 553C B7B8 uid David Chin <david.w.h.chin AT gmail.com> uid David Chin <dwchin AT lroc.harvard.edu> uid David Chin <dwchin.lroc AT gmail.com> ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Math-atlas-devel mailing list Math-atlas-devel@... https://lists.sourceforge.net/lists/listinfo/math-atlas-devel |
|
|
Re: C++ header filesOn Tue, Jun 24, 2008 at 08:27:59PM -0400, David Chin wrote:
> The __cplusplus macro is part of the ISO C++ standard, defined > precisely because the standards committee knew (presumably) that there > would be people who would want to use their old plain C stuff. > > Similarly, ISO C has the macro __STDC__ defined. Both true, but irrelevant. The C++ coders have extern "C" so that they can use their old C stuff. The __cplusplus define is so that you can *pretend* that C code is C++ code. > See here: http://docs.sun.com/app/docs/doc/819-5267/bkaep?a=view > > So, it is more than just idiom. It's required of a standards-compliant compiler. No, it's just idiom, because these are C headers that we're talking about. Done properly, the C++ code would have: extern "C" { #include <atlas.h> } and then everyone would be happy, and there would be no need for spurious #ifdef bracketing in the C header. The problem is the whole notion that a header file can meaningfully be both a C header file and a C++ header file. If you replace C++ by, say, Eiffel in that sentence, the statement gets a bit more obvious. > Cheers, > Dave > > On Tue, Jun 24, 2008 at 7:13 PM, Andrew Reilly > <andrew-atlas@...> wrote: > > On Tue, Jun 24, 2008 at 05:50:10PM -0500, skip@... wrote: > >> Clint> #ifdef __cplusplus > >> Clint> extern "C" > >> Clint> { > >> Clint> #endif > >> Clint> .... > > > >> That is the standard idiom. It will instruct the C++ compiler to not mangle > >> the names between the braces (C linkage). C compilers will not see it. C compilers mightn't see it, but C coders will, and they'll cringe every time. I know that I do. Cheers, -- Andrew ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Math-atlas-devel mailing list Math-atlas-devel@... https://lists.sourceforge.net/lists/listinfo/math-atlas-devel |
| Free embeddable forum powered by Nabble | Forum Help |