Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling convention for C99 bool? #6529

Closed
binarybana opened this issue Apr 15, 2014 · 10 comments
Closed

calling convention for C99 bool? #6529

binarybana opened this issue Apr 15, 2014 · 10 comments
Labels
compiler:codegen Generation of LLVM IR and native code needs decision A decision on this change is needed

Comments

@binarybana
Copy link
Contributor

Whereas it is mentioned in the documentation. I'm not sure whether this is a documentation bug or if Cbool is supposed to be defined. If the former, then what is the recommended way to get the implementation specific size of Bool?

@JeffBezanson
Copy link
Member

I think we should remove Cbool since bool is not a standard C type.
Julia Bool is 1 byte; sizeof will tell you.

@stevengj
Copy link
Member

bool is a standard C type (defined in <stdbool.h>) as of C99.

@binarybana
Copy link
Contributor Author

Not sure if this is relevant here, but in my case I'm trying to call into a C++ function with a bool argument. From what I can tell, the size of C99 bool does not necessarily equal a C++ bool, and the behavior of extern "C" is implementation specific. But trying sizeof(Cbool) was my first guess.

@StefanKarpinski
Copy link
Member

The difference between C99 and C++ bool makes me think we should maybe not have this.

@pao
Copy link
Member

pao commented Apr 15, 2014

C99bool vs. Cppbool?

@tknopp
Copy link
Contributor

tknopp commented Apr 15, 2014

Are there compilers/platforms (C++/C11) where sizeof(bool)!=1?

@binarybana
Copy link
Contributor Author

According to this (p. 6) it is 2 for 16bit Microsoft, and according to msdn it was 4 in Visual C++ 4.2.

@nolta
Copy link
Member

nolta commented Apr 15, 2014

VC++ 4.2 is, what, 17 years old?

@tknopp
Copy link
Contributor

tknopp commented Apr 15, 2014

:-) Ok I provoked this answer. My impression was that the Julia FFI makes certain assumptions anyway (e.g. sizeof(int) == 4) which are not required by the C or C++ standard. Thus if all currently by Julia supported platforms have sizeof(bool)==1, it would be safe to just make this assumption.

JeffBezanson added a commit that referenced this issue Apr 29, 2014
I don't know what the calling convention is for C99 bool, so we'll have
to deal with this later.
@JeffBezanson JeffBezanson changed the title Cbool not defined calling convention for C99 bool? Apr 29, 2014
@ihnorton ihnorton added needs decision A decision on this change is needed compiler:codegen Generation of LLVM IR and native code labels Mar 25, 2015
@vtjnash vtjnash closed this as completed Mar 25, 2016
@nstiurca
Copy link
Contributor

nstiurca commented Jun 3, 2018

Sorry to necromance this, but I am working on wrapping a C library which uses bool as defined by <stdbool.h> in C99.

Although I understand that a lot of C codes hack their way around bool in ad hoc ways, it seems very strange that Julia buries its head in the sand on the issue. What is the recommended way to handle C99 bool in Julia FFI? Can we add such a recommendation to the Julia docs perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

10 participants