1. Rob ??

Rob
  I still do not understand the passing a "C" structure in Euphoria.
  You say that 4 or fewer bytes will be assigned 4 bytes in a
  structure.

  Does that mean that a single byte takes 4 bytes ?

  How do you poke and peek floats and doubles into memory/structure ?

  How much do you allocate for floats and doubles in a structure ?

  Normally when I pass the address of a structure to windows it knows
  the layout of that structure's offsets and size because of the definition
  of that structure in the header file.

  When you pass that structure in your format to windows, Isn't windows
  going to be using the wrong offsets when it trys to access that
  structure ?

  Will you please clear this up for me.
  Thanks
Bernie

new topic     » topic index » view message » categorize

2. Re: Rob ??

Bernie Ryan writes:
> I still do not understand the passing a "C" structure in
> Euphoria. You say that 4 or fewer bytes will be assigned
> 4 bytes in a structure.
> Does that mean that a single byte takes 4 bytes ?

A parameter of 4 or fewer bytes will be pushed as 4 bytes
*on the call stack*.

In a C *structure*, you could have 4 single-byte fields declared
in a row. A C compiler will allocate them as one byte each.
Similarly, if you declare 2 consecutive C short ints
(2 bytes each), the C compiler will allocate them consecutively
as 2 bytes each. The rule, as I understand it, is that 4-byte
quantities must start on a nice 4-byte boundary in memory.
2-byte quantities must start on a 2-byte boundary (i.e. an
even address), and single-byte quantities can start anywhere.
The C compiler will leave empty filler bytes to achieve
this alignment.

> How do you poke and peek floats and doubles
> into memory/structure ?
> How much do you allocate for floats and doubles in a structure?

You use atom_to_float64() or atom_to_float32() to create
a sequence of 4 or 8 bytes. You then poke that into memory.
Or, you peek 4 or 8 bytes into a sequence, and use
float32_to_atom() or float64_to_atom().

I believe that both floats (4 bytes) and doubles (8 bytes)
must be aligned on a 4-byte boundary in a standard
WIN32 C structure.

> Normally when I pass the address of a structure to windows
> it knows the layout of that structure's offsets and size because
> of the definition of that structure in the header file.
> When you pass that structure in your format to windows,
> Isn't windows going to be using the wrong offsets when it
> trys to access that structure?

That's the idea. You have to mimic the layout in memory
that a C compiler would use when it compiles a structure
declaration.

About 90% of the fields in C structures under WIN32 are
either 4-byte integers or 4-byte pointers, so it's usually
pretty easy to figure out the offsets of the fields in memory.

If you program in C you won't have to calculate these offsets,
but then you're stuck using C with all of its shortcomings
compared to Euphoria. People who use Win32Lib or Llama
or some other "wrapper" for WIN32 can avoid most of this
low-level byte-counting work and just call the Euphoria
routines that someone else has provided.

Regards,
     Rob Craig
     Rapid Deployment Software
     http://members.aol.com/FilesEu/

new topic     » goto parent     » topic index » view message » categorize

3. Re: Rob ??

Rob
  Thank You for your reply.
Bernie

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu