[cfe-dev] [libc++abi] use of <stddef.h> vs. <cstddef> etc.
G M
gmisocpp at gmail.com
Mon Oct 14 20:57:25 PDT 2013
Hi Florian
On Tue, Oct 15, 2013 at 9:34 AM, Florian Kutscherauer <
florian.kutscherauer at gmx.at> wrote:
> Dear developers,
>
>
> I'm new to LLVM, so please don't bite off my head if this is a dumb
> question.
>
> I've noticed that some of the C++ files (both headers and bodies) include
> C-headers, like <stddef.h>, <assert.h> etc., while others use the
> corresponding C++-headers, like <cstddef>, <cassert>, and so on.
>
> So, I was wondering the reason for that might be: Is this just out of
> habit and custom, or is there more to it?
>
>
> Best regards,
>
> Flo.
>
I think in general you'd want to use the C++ headers, not the C headers
I.e. prefer cstdio over stdio.h.
One exception is when coding inside of libcxx itself (as opposed to using
it). There you are usually implementing the C++ header itself and including
the C header is often the necessary thing to do for one reason or another.
Sometimes though it might be it's own C++ header that it needs to reference
depending on the case in question.
You might of course want to reference the C header if the header file is
going to be compiled by a C compiler instead of a C++ one.
Generally it's quite a common case is that people use the C headers in C++
by mistake or occasionally because of some compatibility problem they are
trying to avoid. The Ninja project is one where I see a lot of C references
that I think could be changed to C++ but that was actively refused when I
suggested it. So I don't know all the reasons why people do this but it's
quite common. I'd generally stick to the rule if your code is in a c++
program and you're not aware of any problem or trying to share the header
with a C program, use the C++ headers, sometimes they provide useful
overloads of similar functions in the C headers. Sometimes they can
conflict too (he says with one such example in mind, coming to a forum near
you soon lol)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131015/24fc3de7/attachment.html>
More information about the cfe-dev
mailing list