Re: [Haskell-cafe] Begginer question about alignment in Storable

2008-11-15 Thread Michael D. Adams
If you are using hsc2hs (if you are using Cabal this is easy; just
rename the file to *.hsc and Cabal will take care of the rest), then
there is a macro for making this easier and so you don't have to think
about it.

First, place the following at the top of your source file:

#let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t
(y__); }, y__)

Then #{alignment c_type} will always be expanded by hsc2hs to the
correct alignment for the C type named c_type.

On Sat, Nov 15, 2008 at 3:29 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need to make the following structure into
> an instance of Storable:
>
> struct {
>  double w[2];
> }
>
> Can I assume that its function 'alignment' should
> return the same as "alignment (1::CDouble)"? Or
> should it be "2 * alignment (1::CDouble)"?
>
> (I've read the wikipedia article about memory alignment,
> and what I understand is that there's a better alignment
> for hardware efficiency but compilers and programmers can
> do almost anything about it. What can I do when writing
> a library wrapper if I don't know what kind of compiler
> pragmas were used in all platforms that library was
> compiled?)
>
> Thanks,
> Maurício
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Begginer question about alignment in Storable

2008-11-15 Thread Bulat Ziganshin
Hello Maurí­cio,

Saturday, November 15, 2008, 11:29:23 PM, you wrote:

> struct {
>double w[2];
> }

> Can I assume that its function 'alignment' should
> return the same as "alignment (1::CDouble)"? Or
> should it be "2 * alignment (1::CDouble)"?

secind - definitely not. first - probably yes


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Begginer question about alignment in Storable

2008-11-15 Thread Maurí­cio

Hi,

I need to make the following structure into
an instance of Storable:

struct {
  double w[2];
}

Can I assume that its function 'alignment' should
return the same as "alignment (1::CDouble)"? Or
should it be "2 * alignment (1::CDouble)"?

(I've read the wikipedia article about memory alignment,
and what I understand is that there's a better alignment
for hardware efficiency but compilers and programmers can
do almost anything about it. What can I do when writing
a library wrapper if I don't know what kind of compiler
pragmas were used in all platforms that library was
compiled?)

Thanks,
Maurício

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe