Jump to page: 1 2
Thread overview
D vs C Char
Jun 29, 2005
Trevor Parscal
Jun 29, 2005
Brad Beveridge
Jun 29, 2005
Trevor Parscal
Jun 29, 2005
Brad Beveridge
Jun 29, 2005
Trevor Parscal
Jun 29, 2005
Trevor Parscal
Jun 30, 2005
Mike Parker
Jun 30, 2005
brad beveridge
Jun 30, 2005
Trevor Parscal
Jul 03, 2005
Bruno Medeiros
June 29, 2005
OK, so I am still having trouble with this FreeType library, and ... The  people from the FreeType newsgroup told me..


- do not use the D 'char' for C 'char'. That's because
  it's default initializer is 0xFF instead of 0, and this
  will cause all kinds of subtle problems when used
  naively in D code.

So what do i use instead? byte? Isn't the intializer the same?

-- 
Thanks,
Trevor Parscal
www.trevorparscal.com
trevorparscal@hotmail.com
June 29, 2005
I would use ubyte...

-[Unknown]


> OK, so I am still having trouble with this FreeType library, and ... The  people from the FreeType newsgroup told me..
> 
> 
> - do not use the D 'char' for C 'char'. That's because
>   it's default initializer is 0xFF instead of 0, and this
>   will cause all kinds of subtle problems when used
>   naively in D code.
> 
> So what do i use instead? byte? Isn't the intializer the same?
> 
June 29, 2005
Trevor Parscal wrote:
> OK, so I am still having trouble with this FreeType library, and ... The  people from the FreeType newsgroup told me..
> 
> 
> - do not use the D 'char' for C 'char'. That's because
>   it's default initializer is 0xFF instead of 0, and this
>   will cause all kinds of subtle problems when used
>   naively in D code.
> 
> So what do i use instead? byte? Isn't the intializer the same?
> 
That smells like a bogus answer to me.  Nobody in their right mind should rely on a C compiler to initialise variables.
The only difference between C's char and D's char is that D explicitly defines char to be unsigned, a C compiler may choose to define it as signed or unsigned, depending on architecture/whim.

If there is truely a difference between the default init value, then you can explicitly set the variable.

char c = 0;

BTW, have you got a simple working C example of Freetype that works? Can you convert that to D?  I'm wondering if you're having troubles because of misusing the Freetype API rather than the C/D interface.

Brad
June 29, 2005
Brad Beveridge wrote:
> Trevor Parscal wrote:
> 
>> OK, so I am still having trouble with this FreeType library, and ... The  people from the FreeType newsgroup told me..
>>
>>
>> - do not use the D 'char' for C 'char'. That's because
>>   it's default initializer is 0xFF instead of 0, and this
>>   will cause all kinds of subtle problems when used
>>   naively in D code.
>>
>> So what do i use instead? byte? Isn't the intializer the same?
>>
> That smells like a bogus answer to me.  Nobody in their right mind should rely on a C compiler to initialise variables.
> The only difference between C's char and D's char is that D explicitly defines char to be unsigned, a C compiler may choose to define it as signed or unsigned, depending on architecture/whim.
> 
> If there is truely a difference between the default init value, then you can explicitly set the variable.
> 
> char c = 0;
> 
> BTW, have you got a simple working C example of Freetype that works? Can you convert that to D?  I'm wondering if you're having troubles because of misusing the Freetype API rather than the C/D interface.
> 
> Brad

Thats a good question.. I suppose I should try and do a test with C.. But, its allot of configuration crap just to get FreeType to compile with C at all.. so.. I have been avoiding dealing with that.

They say on the FreeType page, "FreeType will compile on almost any compiler on most platforms without even a single warning".. But, my experience is that it's EXTRMELY difficult to get it to compile at all, and there are so many warnings its hard to see where the errors are.

Anyhoo, I cant even begin to explain how much I wish this worked, and would give my semicolin key to the man who helps me do so.

Thanks,
Trevor Parscal

-- 
Thanks,
Trevor Parscal
www.trevorparscal.com
trevorparscal@hotmail.com
June 29, 2005
Trevor Parscal wrote:
<snip>
> 
> Thats a good question.. I suppose I should try and do a test with C.. But, its allot of configuration crap just to get FreeType to compile with C at all.. so.. I have been avoiding dealing with that.
> 
> They say on the FreeType page, "FreeType will compile on almost any compiler on most platforms without even a single warning".. But, my experience is that it's EXTRMELY difficult to get it to compile at all, and there are so many warnings its hard to see where the errors are.
> 
> Anyhoo, I cant even begin to explain how much I wish this worked, and would give my semicolin key to the man who helps me do so.
> 
> Thanks,
> Trevor Parscal
> 

The documentation has some snippet code examples that look like they'd go together without much trouble.  I did notice one interesting thing, the docs say you should
#include <ftbuild2.h>
#include FT_FREETYPE_H

which looks a little weird to me, I think they are doing some non standard things, and they mention that they are doing magic trickery.

I think that my approach to this would be
1) Write a C program that gets free type working
2) Convert that program to something more like a library, so that it proxies the free type calls that you are actually interested in.
3) Interface your D code to this proxy library/object file.
4) Start directly interfacing to Freetype from D where appropriate.

Unless I understood what was going on in the headers really well, I'd try and take the above approach.

Cheers
Brad
June 29, 2005
Trevor Parscal wrote:

> - do not use the D 'char' for C 'char'. That's because
>   it's default initializer is 0xFF instead of 0, and this
>   will cause all kinds of subtle problems when used
>   naively in D code.
> 
> So what do i use instead? byte? Isn't the intializer the same?

No, as the various D integer initializers are still sane... :-)
It's just the code units and floating points that's "wild".

(As per the table at http://www.digitalmars.com/d/type.html)


It all depends on what they are using "char" for, really ?
If it's ASCII, then _either_ "char" or "ubyte" will do fine.
If they are using char for 8-bit encodings, then it's ubyte.
And if they are using char for UTF-8 (unlikely), then: char.

And for "char*", it doesn't matter much at all really (since
you get a pointer), so most people just stick with the C def.
Even if it's technically wrong in D, since "char*" means UTF-8.
(and not "some random encoding", like its the old C meaning is)


That being said,
I haven't had a problem translating C's "char*" to D's "char*",
in any of the import modules for D that I have done thus far...

I'll feed the freetype2 headers to my C header->D module script,
and see what it comes up with. Minus the weirdo macros, that is.

But don't hold your breath. ;-)
--anders
June 29, 2005
Anders F Björklund wrote:

> I'll feed the freetype2 headers to my C header->D module script,
> and see what it comes up with. Minus the weirdo macros, that is.
> 
> But don't hold your breath. ;-)
> --anders

I would be VERY interested in seeing what you come up with.. Send me a copy if you can once it is under control, or when you give up...

-- 
Thanks,
Trevor Parscal
www.trevorparscal.com
trevorparscal@hotmail.com
June 29, 2005
Trevor Parscal wrote:

> I would be VERY interested in seeing what you come up with.. Send me a copy if you can once it is under control, or when you give up...

They are using macros for *everything*, including names of headers -
so it needs to be preprocessed after conversion... <mutter, mutter>

(I'm not preprocessing before conversion, since the #defines usually
holds a lot of usable information that can be converted into D things)

Wasn't very hard to compile, though ? "./configure && make". Yay, UNIX.

--anders
June 29, 2005
Anders F Björklund wrote:
> Trevor Parscal wrote:
> 
>> I would be VERY interested in seeing what you come up with.. Send me a copy if you can once it is under control, or when you give up...
> 
> 
> They are using macros for *everything*, including names of headers -
> so it needs to be preprocessed after conversion... <mutter, mutter>
> 
> (I'm not preprocessing before conversion, since the #defines usually
> holds a lot of usable information that can be converted into D things)
> 
> Wasn't very hard to compile, though ? "./configure && make". Yay, UNIX.
> 
> --anders

yes.. Yay UNIX, BOOO Windows...

-- 
Thanks,
Trevor Parscal
www.trevorparscal.com
trevorparscal@hotmail.com
June 30, 2005
Trevor Parscal wrote:
> 
> 
> yes.. Yay UNIX, BOOO Windows...
> 

Install Cygwin or MingW + MSYS on Windows and you can do the same thing: ./configure
make
« First   ‹ Prev
1 2