-
Notifications
You must be signed in to change notification settings - Fork 1.5k
C++ interop: Add support for C++ Primitive Types #5263
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
Comments
Note, for now maybe just i8/u8 for char types. We don't have a byte type yet, and we may want a char type. For long, I'll also suggest forcing i64/u64 for now. We don't have Windows testing yet, but we need a clearer decision about how to handle cross-platform. It's possible we'll actually want a platform-dependent type for |
For integer types, discussion with @chandlerc and @zygoloid seems to have leaned (for now, at least):
When transforming Carbon types to C++, always use this mapping. When transforming C++ types to Carbon, fit into these buckets as much as possible. |
Had some further discussion with @chandlerc about this, largely reaffirming the approach that @jonmeow described previously. Some new observations:
|
Thanks a lot for your input! @jonmeow @zygoloid |
Hey, I would like to work on this issue. |
Added support for `short`/`int16_t`. Both function parameters and return values this type will be supported. Demo: ```c++ // hello_short.h #include <cstdint> auto foo_short(int16_t a) -> int16_t; ``` ```c++ // hello_short.cpp #include "hello_short.h" #include <cstdio> auto foo_short(int16_t a) -> int16_t { printf("a = %i \n", a); return a; } ``` ```c++ // main.carbon library "Main"; import Cpp library "hello_short.h"; import Core library "io"; fn Run() -> i32 { var a: i16 = 3; Cpp.foo_short(a); return 0; } ``` ``` $ clang -c hello_short.cpp $ bazel-bin/toolchain/carbon compile main.carbon $ bazel-bin/toolchain/carbon link hello_short.o main.o --output=demo $ ./demo a = 3 ``` Part of #5263
* Split to 4 files: `function_param_int16`, `function_param_int32`, `function_param_unsupported.carbon`, `function_return`. * Add // === headlines on group of file shards. * Rename shard files to shorten them and make them more consistent given the file context. * Deduplicate identical .h files and group their tests. Potential future improvements: * Split further. For example, pointers and references might be somewhat separate from int primitives. * Remove `import_` shard file prefix, as it repeats itself, but leaving for now as it makes it more explicit. Part of carbon-language#5263
* Split to 4 files: `function_param_int16`, `function_param_int32`, `function_param_unsupported.carbon`, `function_return`. * Add // === headlines on group of file shards. * Rename shard files to shorten them and make them more consistent given the file context. * Deduplicate identical .h files and group their tests. Potential future improvements: * Split further. For example, pointers and references might be somewhat separate from int primitives. * Remove `import_` shard file prefix, as it repeats itself, but leaving for now as it makes it more explicit. Part of carbon-language#5263
…5457) * Split to 4 files: `function_param_int16`, `function_param_int32`, `function_param_unsupported.carbon`, `function_return`. * Add // === headlines on group of file shards. * Rename shard files to shorten them and make them more consistent given the file context. * Deduplicate identical .h files and group their tests. Potential future improvements: * Split further. For example, pointers and references might be somewhat separate from int primitives. * Remove `import_` shard file prefix, as it repeats itself, but leaving for now as it makes it more explicit. Part of #5263
The primitive types mapping proposal (#5448) is now open for review. |
Thanks @rahiladmin for your interest in participating to this issue. While the proposal (#5448) is still in review, the mapping of |
Uh oh!
There was an error while loading. Please reload this page.
Use Carbon: C++ Interop - Primitive Types doc as a reference for the type mappings.
The text was updated successfully, but these errors were encountered: