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

add typealiases for exact C-compatible types #2370

Merged
merged 1 commit into from
Feb 27, 2013
Merged

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Feb 20, 2013

some more typealias's for consideration in the list that I forgot initially (in decreasing order of my interest level of actually having them added):

typealias Cfloat Float32
typealias Cdouble Float64
typealias Cstring Ptr{Uint8}
typealias Cargv Ptr{Ptr{Uint8}}
typealias Cptr Ptr{Void}

(travis build fails because I'm using OS_NAME before build_h.jl got included in the sysimg. I think it should be moved much earlier)

@nolta
Copy link
Member

nolta commented Feb 20, 2013

Could we rename Cshortint, Cushortint, Cptrdiff, and Csize to Cshort, Cushort, Cptrdiff_t, and Csize_t?

I'm not sure we need Cstring, Cargv, & Cptr because Ptr{Cchar}, Ptr{Ptr{Cchar}}, & Ptr{Void} are pretty clear.

@StefanKarpinski
Copy link
Sponsor Member

I agree with @nolta's suggestions here. Also like having these aliases. Thanks, @vtjnash.

@stevengj
Copy link
Member

Nice! I think we should have Cstring if only because it is more readable than Ptr{Cchar}.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Feb 20, 2013

It wasn't clear to me whether Cptrdiff_t or Cptrdiff was more correct. By analogy between Julia and C99 types, I dropped the _t, but I if those are well known enough on their own, I can follow @nolta's suggestion.

@stevengj
Copy link
Member

I would just delete it, to be honest. The only real reason to have complex integers is for fixed-point arithmetic, as far as I can tell, but fixed-point complex arithmetic makes very little sense on any architecture with hardware multipliers.

If Julia ever begins to target embedded systems, you could always add this later, or the programmer could just use ComplexPair{Cint} manually, but adding this obcure and easily misused nonstandard type now seems to me like it does more harm than good.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Feb 25, 2013

would it make sense to add
typealias Carray Ptr{Void}
as a declaration mostly for use in Julia type declarations (since I've found it pretty common that someone expects julia's Array type is equivalent to a Cptr)

@stevengj
Copy link
Member

Carray seems to break the convention that Cfoo corresponds to C type foo; this inconsistency seems unhelpful to me. Ptr{T} is clearer (since CT* is out of the question). On the other hand, I like Cstring, so I am inconsistent myself.

@StefanKarpinski
Copy link
Sponsor Member

I agree with @stevengj about Carray.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Feb 25, 2013

there's also the possibility of typealias Carray Ptr (or is that typealias Carray{T} Ptr{T}?). either way, i think this is good to merge now, without it

i imagined that you could reasonably have in your C code typedef char *string, so that Cstring is consistent. it's less clear to me what an array in c actually is since it can be either [] or * depending on context, so the idea that it is simply a Ptr{T} isn't as consistent

@stevengj
Copy link
Member

You have (on non-Windows):

typealias Culong Int

Shouldn't this be Uint?

JeffBezanson added a commit that referenced this pull request Feb 27, 2013
add typealiases for exact C-compatible types
@JeffBezanson JeffBezanson merged commit a751bac into master Feb 27, 2013
@pao
Copy link
Member

pao commented Feb 27, 2013

@stevengj Looks like Jeff patched it up after the merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants