add typealiases for exact C-compatible types #2370

Merged
merged 1 commit into from Feb 27, 2013

Conversation

Projects
None yet
6 participants
@vtjnash
Member

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

This comment has been minimized.

Show comment Hide comment
@nolta

nolta Feb 20, 2013

Member

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.

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

This comment has been minimized.

Show comment Hide comment
@StefanKarpinski

StefanKarpinski Feb 20, 2013

Owner

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

Owner

StefanKarpinski commented Feb 20, 2013

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

@stevengj

This comment has been minimized.

Show comment Hide comment
@stevengj

stevengj Feb 20, 2013

Owner

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

Owner

stevengj commented Feb 20, 2013

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

@vtjnash

This comment has been minimized.

Show comment Hide comment
@vtjnash

vtjnash Feb 20, 2013

Member

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.

Member

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

This comment has been minimized.

Show comment Hide comment
@stevengj

stevengj Feb 24, 2013

Owner

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.

Owner

stevengj commented Feb 24, 2013

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

This comment has been minimized.

Show comment Hide comment
@vtjnash

vtjnash Feb 25, 2013

Member

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)

Member

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

This comment has been minimized.

Show comment Hide comment
@stevengj

stevengj Feb 25, 2013

Owner

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.

Owner

stevengj commented Feb 25, 2013

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

This comment has been minimized.

Show comment Hide comment
@StefanKarpinski

StefanKarpinski Feb 25, 2013

Owner

I agree with @stevengj about Carray.

Owner

StefanKarpinski commented Feb 25, 2013

I agree with @stevengj about Carray.

@vtjnash

This comment has been minimized.

Show comment Hide comment
@vtjnash

vtjnash Feb 25, 2013

Member

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

Member

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

This comment has been minimized.

Show comment Hide comment
@stevengj

stevengj Feb 26, 2013

Owner

You have (on non-Windows):

typealias Culong Int

Shouldn't this be Uint?

Owner

stevengj commented Feb 26, 2013

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

Merge pull request #2370 from JuliaLang/jn/ctypealias
add typealiases for exact C-compatible types

@JeffBezanson JeffBezanson merged commit a751bac into master Feb 27, 2013

1 check passed

default The Travis build passed
Details
@pao

This comment has been minimized.

Show comment Hide comment
@pao

pao Feb 27, 2013

Member

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

Member

pao commented Feb 27, 2013

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

@StefanKarpinski

This comment has been minimized.

Show comment Hide comment
@StefanKarpinski

StefanKarpinski Feb 27, 2013

Owner

Nice. If we start using these consistently everywhere, does that make the Win64 port easier?

Owner

StefanKarpinski commented on bc92507 Feb 27, 2013

Nice. If we start using these consistently everywhere, does that make the Win64 port easier?

This comment has been minimized.

Show comment Hide comment

This comment has been minimized.

Show comment Hide comment
@vtjnash

vtjnash Feb 27, 2013

Member

@StefanKarpinski yes, these match the intended sizes of the Win64 port

Member

vtjnash replied Feb 27, 2013

@StefanKarpinski yes, these match the intended sizes of the Win64 port

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment