Re: c question

2010-04-23 Thread Eitan Adler
 - use a matrix is faster than use a linked list?

For what?
For insertion and deletion no - linked list is faster. For sequential
access they are the same speed (forgetting look-ahead caching). For
random access matrix is faster.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question

2010-04-23 Thread Joerg Sonnenberger
On Fri, Apr 23, 2010 at 06:18:46PM +0300, Eitan Adler wrote:
  - use a matrix is faster than use a linked list?
 
 For what?
 For insertion and deletion no - linked list is faster. For sequential
 access they are the same speed (forgetting look-ahead caching). For
 random access matrix is faster.

Actually -- it depends. Removing the tail and inserting at tail is
amortised constant time for arrays if done using the double-on-full
trick. In that case, array can be the faster datastructure too.

Joerg
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question

2010-04-23 Thread Pieter de Goeje
On Friday 23 April 2010 17:40:12 Joerg Sonnenberger wrote:
 On Fri, Apr 23, 2010 at 06:18:46PM +0300, Eitan Adler wrote:
   - use a matrix is faster than use a linked list?
 
  For what?
  For insertion and deletion no - linked list is faster. For sequential
  access they are the same speed (forgetting look-ahead caching). For
  random access matrix is faster.

 Actually -- it depends. Removing the tail and inserting at tail is
 amortised constant time for arrays if done using the double-on-full
 trick. In that case, array can be the faster datastructure too.

Random deletes can be made O(1) if you don't care about the order of the 
elements in an array.

- Pieter
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


c question

2010-04-09 Thread Leinier Cruz Salfran
hello all

i want to know your oppinions about this:

- use a matrix is faster than use a linked list?


example:

char *szColumnName[10];
unsigned short iColumnAge[10];


struct _llList {
  struct _llList *prev, *next;
  char szName[64];
  unsigned short iAge;
};
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question

2010-04-09 Thread Alexander Churanov
2010/4/9 Leinier Cruz Salfran salfrancl.lis...@gmail.com

 - use a matrix is faster than use a linked list?

 example:

 char *szColumnName[10];
 unsigned short iColumnAge[10];


 struct _llList {
  struct _llList *prev, *next;
  char szName[64];
  unsigned short iAge;
  };


Leinier ,

This depends on what kind of operations are performed. For sequential
traversing, both are very appropriate. However, you can not perform a binary
search on a list. You also can not combine two arrays into a single one with
constant complexity.

Lists also have greater memory overhead for small structures.

My advice: always use arrays.
Use lists if:

1) Copying items when the dynamic arrays grows is inappropriate.
2) List-specific operations like O(1) splicing or O(1) insertions and
deletions are required.

Alexander Churanov
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question

2010-04-09 Thread Leinier Cruz Salfran
On Fri, Apr 9, 2010 at 10:52 AM, Alexander Churanov
alexanderchura...@gmail.com wrote:
 2010/4/9 Leinier Cruz Salfran salfrancl.lis...@gmail.com

 - use a matrix is faster than use a linked list?

 example:

 char *szColumnName[10];
 unsigned short iColumnAge[10];


 struct _llList {
  struct _llList *prev, *next;
  char szName[64];
  unsigned short iAge;
  };


 Leinier ,
 This depends on what kind of operations are performed. For sequential
 traversing, both are very appropriate. However, you can not perform a binary
 search on a list. You also can not combine two arrays into a single one with
 constant complexity.
 Lists also have greater memory overhead for small structures.
 My advice: always use arrays.
 Use lists if:
 1) Copying items when the dynamic arrays grows is inappropriate.
 2) List-specific operations like O(1) splicing or O(1) insertions and
 deletions are required.
 Alexander Churanov


hello alexander

i supposed that a matrix is much faster .. i coded my program to use
matrix in that portion but i sent the question to see what others
think about this

thanks
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question

2010-04-09 Thread KAYVEN RIESE

On Fri, 9 Apr 2010, Leinier Cruz Salfran wrote:


hello all

i want to know your oppinions about this:

- use a matrix is faster than use a linked list?


yes.




example:

char *szColumnName[10];
unsigned short iColumnAge[10];


struct _llList {
 struct _llList *prev, *next;
 char szName[64];
 unsigned short iAge;
};
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org



*--*
  Kayven Riese, BSCS, MS (Physiology and Biophysics)
  (415) 902 5513 cellular
  http://kayve.net
  Webmaster http://ChessYoga.org
*--*
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-07-08 Thread Alexander Best
thx for all the great help guys.

cheers,
alex

Carlos A. M. dos Santos schrieb am 2009-07-02:
 2009/7/2 Dag-Erling Smørgrav d...@des.no:
  Alexander Best alexbes...@math.uni-muenster.de writes:
      for (i=0; i  sizeof(hdr-nintendo_logo); i++)
          fprintf(stderr, %x, hdr-nintendo_logo[i]);

  What will this print if nintendo_logo is { 0x01, 0x02, 0x03, 0x04
  }?

 Good catch. It will print 0x1234 but it should print 0x01020304.
 My example has the same error. The conversion specification should be
 %02x, not just %x.

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-07-04 Thread Giorgos Keramidas
On Tue, 30 Jun 2009 20:21:03 +0200 (CEST), Alexander Best 
alexbes...@math.uni-muenster.de wrote:
 thanks. now the output gets redirected using . i'm quite new to programming
 under unix. sorry for the inconvenience.

 so i guess there is no really easy way to output an inhomogeneous struct to
 stdout without using a loop to output each array contained in the struct.

No not really.  You have to do the sizeof() dance.

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-07-04 Thread Giorgos Keramidas
On Wed, 01 Jul 2009 00:06:05 +0200 (CEST), Alexander Best 
alexbes...@math.uni-muenster.de wrote:
 thanks for all the help. i decided to take the pill and coded all the
 fprintfs by hand. here's the result. usually i'd stick to a higher
 level languag, but i need C's inline assembly support:

 struct Header
 {
 u_int8_t rom_entry[4];
 u_int8_t nintendo_logo[156];

...

 fprintf(stderr, \nNintendo Logo: 0x);
 for (i=0; i  sizeof(hdr-nintendo_logo); i++)
 fprintf(stderr, %x, hdr-nintendo_logo[i]);

Note that %x will only print *one* digit for values smaller than 16,
i.e. printf(%x, 10) = a, so it may be useful to use %02x instead.

 fprintf(stderr, \nFixed Value: 0x);
 fprintf(stderr, %x, hdr-fixed_val);

For multi-byte fields, it makes sense to print 0x first and then
iterate.  For single-byte values, it's probably a tiny bit faster to go
only _once_ through for *printf() family formatter, i.e.:

- fprintf(stderr, \nFixed Value: 0x);
- fprintf(stderr, %x, hdr-fixed_val);
+ fprintf(stderr, \nFixed Value: 0x%x, hdr-fixed_val);

Another nit that I noticed is that your last line doesn't end with \n:

fprintf(stderr, \nJoybus Entry Point: 0x);
for (i=0; i  sizeof(hdr-joybus_entry); i++) fprintf(stderr, %x,
hdr-joybus_entry[i]);

Some terminal setups will *not* output the last line if it does not
finish properly with a \n, so it may be worth editing the code to
avoid the \nXXX format idiom, and go for a format style that puts
\n at the _end_ of output lines:

fprintf(stderr, Nintendo Logo: 0x);
for (i = 0; i  sizeof(hdr-nintendo_logo); i++)
 fprintf(stderr, %02x, hdr-nintendo_logo[i]);
fprintf(stderr, \n);

fprintf(stderr, Fixed Value: 0x%02x\n, hdr-fixed_val);

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-07-04 Thread Igor Mozolevsky
2009/7/4 Giorgos Keramidas keram...@ceid.upatras.gr:

[snip]

s/0x%/%#.2hh/g

--
Igor
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-07-02 Thread Dag-Erling Smørgrav
Alexander Best alexbes...@math.uni-muenster.de writes:
 for (i=0; i  sizeof(hdr-nintendo_logo); i++)
 fprintf(stderr, %x, hdr-nintendo_logo[i]);

What will this print if nintendo_logo is { 0x01, 0x02, 0x03, 0x04 }?

DES
-- 
Dag-Erling Smørgrav - d...@des.no
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-07-02 Thread Carlos A. M. dos Santos
2009/7/2 Dag-Erling Smørgrav d...@des.no:
 Alexander Best alexbes...@math.uni-muenster.de writes:
     for (i=0; i  sizeof(hdr-nintendo_logo); i++)
         fprintf(stderr, %x, hdr-nintendo_logo[i]);

 What will this print if nintendo_logo is { 0x01, 0x02, 0x03, 0x04 }?

Good catch. It will print 0x1234 but it should print 0x01020304.
My example has the same error. The conversion specification should be
%02x, not just %x.

-- 
My preferred quotation of Robert Louis Stevenson is You cannot
make an omelette without breaking eggs. Not because I like the
omelettes, but because I like the sound of eggs being broken.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-07-01 Thread Carlos A. M. dos Santos
On Tue, Jun 30, 2009 at 7:54 PM, Alfred Perlsteinalf...@freebsd.org wrote:
 Hey Alex,

 People frown on macros, but this could be a good one:

 #define SPRINT(f, fmt) \
        do {\
                for (_i = 0; _i  sizeof(f)/sizeof(f[0]); i++) \
                        printf(fmt, f[i]); \
        }while(0)

 :D

 This should allow you to point to any _array_ and print each
 element of it using format fmt.

 Example:
 SPRINT(Header-game_title, %c);

Yes, it works, but using a loop to print a character array one char at
a time is terribly inefficient.

-- 
My preferred quotation of Robert Louis Stevenson is You cannot
make an omelette without breaking eggs. Not because I like the
omelettes, but because I like the sound of eggs being broken.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-07-01 Thread Carlos A. M. dos Santos
On Tue, Jun 30, 2009 at 7:06 PM, Alexander
Bestalexbes...@math.uni-muenster.de wrote:
 thanks for all the help. i decided to take the pill and coded all the fprintfs
 by hand. here's the result. usually i'd stick to a higher level languag, but i
 need C's inline assembly support:

    struct Header
    {
        u_int8_t rom_entry[4];
        u_int8_t nintendo_logo[156];
        u_char game_title[12];
        u_char game_code[4];
        u_char maker_code[2];
        u_int8_t fixed_val;
        u_int8_t unit_code;
        u_int8_t device_type;
        u_int8_t reserved_area1[7];
        u_int8_t software_version;
        u_int8_t complement_check;
        u_int8_t reserved_area2;
        u_int8_t ram_entry[4];
        u_int8_t boot_mode;
        u_int8_t slave_id;
        u_int8_t unused_area[26];
        u_int8_t joybus_entry[4];
    };

    struct Header * hdr = rom;
    int i;

    fprintf(stderr, ROM Entry: 0x);
    for (i=0; i  4; i++) fprintf(stderr, %x, hdr-rom_entry[i]);
    fprintf(stderr, \nNintendo Logo: 0x);
    for (i=0; i  sizeof(hdr-nintendo_logo); i++) fprintf(stderr, %x,
    hdr-nintendo_logo[i]);
    fprintf(stderr, \nGame Title: %s,  hdr-game_title);
    fprintf(stderr, \nGame Code: %s,  hdr-game_code);
    fprintf(stderr, \nMaker Code: %s,  hdr-maker_code);
    fprintf(stderr, \nFixed Value: 0x);
    fprintf(stderr, %x, hdr-fixed_val);
    fprintf(stderr, \nUnit Code: 0x);
    fprintf(stderr, %x, hdr-unit_code);
    fprintf(stderr, \nDevice Type: 0x);
    fprintf(stderr, %x, hdr-device_type);
    fprintf(stderr, \nReserved Area: 0x);
    for (i=0; i  sizeof(hdr-reserved_area1); i++) fprintf(stderr, %x,
    hdr-reserved_area1[i]);
    fprintf(stderr, \nSoftware Version: 0x);
    fprintf(stderr, %x, hdr-software_version);
    fprintf(stderr, \nComplement Check: 0x);
    fprintf(stderr, %x, hdr-complement_check);
    fprintf(stderr, \nReserved Area: 0x);
    fprintf(stderr, %x, hdr-reserved_area2);
    fprintf(stderr, \nRAM Entry Point: 0x);
    for (i=0; i  sizeof(hdr-ram_entry); i++) fprintf(stderr, %x,
    hdr-ram_entry[i]);
    fprintf(stderr, \nBoot Mode: 0x);
    fprintf(stderr, %x, hdr-boot_mode);
    fprintf(stderr, \nSlave ID: 0x);
    fprintf(stderr, %x, hdr-slave_id);
    fprintf(stderr, \nUnused Area: 0x);
    for (i=0; i  sizeof(hdr-unused_area); i++) fprintf(stderr, %x,
    hdr-unused_area[i]);
    fprintf(stderr, \nJoybus Entry Point: 0x);
    for (i=0; i  sizeof(hdr-joybus_entry); i++) fprintf(stderr, %x,
    hdr-joybus_entry[i]);

The code below is a bit more efficient and easier to read. It is also
safer, since it limits the width of the %s conversions to the sizes of
the corresponding arrays.

fprintf(stderr, ROM Entry: 0x);
for (i=0; i  4; i++)
fprintf(stderr, %x, hdr-rom_entry[i]);
fprintf(stderr, \nNintendo Logo: 0x);
for (i=0; i  sizeof(hdr-nintendo_logo); i++)
fprintf(stderr, %x, hdr-nintendo_logo[i]);
fprintf(stderr,
\nGame Title: %.*s
\nGame Code: %.*s
\nMaker Code: %.*s
\nFixed Value: 0x%x
\nUnit Code: 0x%x
\nDevice Type: 0x%x
\nReserved Area: 0x,
sizeof(hdr-game_title), hdr-game_title,
sizeof(hdr-game_code), hdr-game_code,
sizeof(hdr-maker_code), hdr-maker_code,
hdr-fixed_val,
hdr-unit_code,
hdr-device_type);
for (i=0; i  sizeof(hdr-reserved_area1); i++)
fprintf(stderr, %x, hdr-reserved_area1[i]);
fprintf(stderr,
\nSoftware Version: 0x%x
\nComplement Check: 0x%x
\nReserved Area: 0x%x
\nRAM Entry Point: 0x,
hdr-software_version,
hdr-complement_check,
hdr-reserved_area2);
for (i=0; i  sizeof(hdr-ram_entry); i++)
fprintf(stderr, %x, hdr-ram_entry[i]);
fprintf(stderr,
\nBoot Mode: 0x%x
\nSlave ID: 0x%x
\nUnused Area: 0x,
hdr-boot_mode,
hdr-slave_id);
for (i=0; i  sizeof(hdr-unused_area); i++)
fprintf(stderr, %x, hdr-unused_area[i]);
fprintf(stderr, \nJoybus Entry Point: 0x);
for (i=0; i  sizeof(hdr-joybus_entry); i++)
fprintf(stderr, %x, hdr-joybus_entry[i]);
fprintf(stderr, \n);



-- 
My preferred quotation of Robert Louis Stevenson is You cannot
make an omelette without breaking eggs. Not because I like the
omelettes, but because I like the sound of eggs being broken.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


c question: *printf'ing arrays

2009-06-30 Thread Alexander Best
hi there,

i need to output the header of a file to stdout. the header looks like this:

struct Header
{
u_int8_t rom_entry[4];
u_int8_t nintendo_logo[156];
u_char game_title[12];
u_char game_code[4];
u_char maker_code[2];
u_int8_t fixed_val;
u_int8_t unit_code;
u_int8_t device_type;
u_int8_t reserved_area1[7];
u_int8_t software_version;
u_int8_t complement_check;
u_int8_t reserved_area2;
u_int8_t ram_entry[4];
u_int8_t boot_mode;
u_int8_t slave_id;
u_int8_t unused_area[26];
u_int8_t joybus_entry[4];
};

if there a way to use printf or some other variant of *printf without using
sizeof()-loops for all the arrays?

cheers.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Tom Evans
On Tue, 2009-06-30 at 18:12 +0200, Alexander Best wrote:
 hi there,
 
 i need to output the header of a file to stdout. the header looks like this:
 
 struct Header
 {
 u_int8_t rom_entry[4];
 u_int8_t nintendo_logo[156];
 u_char game_title[12];
 u_char game_code[4];
 u_char maker_code[2];
 u_int8_t fixed_val;
 u_int8_t unit_code;
 u_int8_t device_type;
 u_int8_t reserved_area1[7];
 u_int8_t software_version;
 u_int8_t complement_check;
 u_int8_t reserved_area2;
 u_int8_t ram_entry[4];
 u_int8_t boot_mode;
 u_int8_t slave_id;
 u_int8_t unused_area[26];
 u_int8_t joybus_entry[4];
 };
 
 if there a way to use printf or some other variant of *printf without using
 sizeof()-loops for all the arrays?
 
 cheers.

None of your arrays are dynamically sized, so surely 
write(fd, hdr, sizeof(Header));
would do the trick?

Cheers

Tom

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Alexander Best
thanks. but that simply dumps the contents of the struct to stdout. but since
most of the struct's contents aren't ascii the output isn't really of much
use.

cheers.

Tom Evans schrieb am 2009-06-30:
 On Tue, 2009-06-30 at 18:12 +0200, Alexander Best wrote:
  hi there,

  i need to output the header of a file to stdout. the header looks
  like this:

  struct Header
  {
  u_int8_t rom_entry[4];
  u_int8_t nintendo_logo[156];
  u_char game_title[12];
  u_char game_code[4];
  u_char maker_code[2];
  u_int8_t fixed_val;
  u_int8_t unit_code;
  u_int8_t device_type;
  u_int8_t reserved_area1[7];
  u_int8_t software_version;
  u_int8_t complement_check;
  u_int8_t reserved_area2;
  u_int8_t ram_entry[4];
  u_int8_t boot_mode;
  u_int8_t slave_id;
  u_int8_t unused_area[26];
  u_int8_t joybus_entry[4];
  };

  if there a way to use printf or some other variant of *printf
  without using
  sizeof()-loops for all the arrays?

  cheers.

 None of your arrays are dynamically sized, so surely
 write(fd, hdr, sizeof(Header));
 would do the trick?

 Cheers

 Tom
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Alexander Best
that works, but i really want to have a pretty output to stdout. i guess i
have to stick with printf and use `for (i=0; i  sizeof(XXX); i++)` for each
array in the struct. just thought i could avoid it.

btw. `./my-program | hexdump` works, but if i do `./my-program  output`
output is being created, but is empty. is this normal?

cheers.

Igor Mozolevsky schrieb am 2009-06-30:
 2009/6/30 Alexander Best alexbes...@math.uni-muenster.de:
  thanks. but that simply dumps the contents of the struct to stdout.
  but since
  most of the struct's contents aren't ascii the output isn't really
  of much
  use.

 How about ./your-program | hexdump ?

 --
 Igor
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Igor Mozolevsky
2009/6/30 Alexander Best alexbes...@math.uni-muenster.de:
 that works, but i really want to have a pretty output to stdout. i guess i
 have to stick with printf and use `for (i=0; i  sizeof(XXX); i++)` for each
 array in the struct. just thought i could avoid it.

 btw. `./my-program | hexdump` works, but if i do `./my-program  output`
 output is being created, but is empty. is this normal?

Depends if you output to stdout or stderr --- `' redirects stdout.


Cheers,
--
Igor
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Alexander Best
should be stdout.


struct Header *hdr = rom;

int new_fd = open(/dev/stdout, O_RDWR);

printf(SIZE: %d\n,sizeof(*hdr));

write(new_fd, hdr, sizeof(*hdr));

close(new_fd);

Igor Mozolevsky schrieb am 2009-06-30:
 2009/6/30 Alexander Best alexbes...@math.uni-muenster.de:
  that works, but i really want to have a pretty output to stdout. i
  guess i
  have to stick with printf and use `for (i=0; i  sizeof(XXX); i++)`
  for each
  array in the struct. just thought i could avoid it.

  btw. `./my-program | hexdump` works, but if i do `./my-program 
  output`
  output is being created, but is empty. is this normal?

 Depends if you output to stdout or stderr --- `' redirects stdout.


 Cheers,
 --
 Igor
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Rick C. Petty
On Tue, Jun 30, 2009 at 08:03:21PM +0200, Alexander Best wrote:
 should be stdout.
 
 
 struct Header *hdr = rom;
 
 int new_fd = open(/dev/stdout, O_RDWR);
 printf(SIZE: %d\n,sizeof(*hdr));
 write(new_fd, hdr, sizeof(*hdr));
 close(new_fd);

Why are you reopening stdout?  It should already be open, so use
fileno(stdout) or just plain STDOUT_FILENO instead of new_fd.

-- Rick C. Petty
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Igor Mozolevsky
2009/6/30 Alexander Best alexbes...@math.uni-muenster.de:
 thanks. but that simply dumps the contents of the struct to stdout. but since
 most of the struct's contents aren't ascii the output isn't really of much
 use.

How about ./your-program | hexdump ?

--
Igor
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Igor Mozolevsky
2009/6/30 Alexander Best alexbes...@math.uni-muenster.de:
 should be stdout.


 struct Header *hdr = rom;

 int new_fd = open(/dev/stdout, O_RDWR);

 printf(SIZE: %d\n,sizeof(*hdr));

 write(new_fd, hdr, sizeof(*hdr));

 close(new_fd);

You should really be checking what open returns, opening /dev/stdout
for reading is a bit weird not sure if that would work, and most
likely it's already open... Just use fileno(...):-

#include unistd.h
#include stdio.h

int main(void) {
  write(fileno(stdout), Hello world!\n, 13);
  return 0;
}

Cheers,
--
Igor
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Alexander Best
thanks. now the output gets redirected using . i'm quite new to programming
under unix. sorry for the inconvenience.

so i guess there is no really easy way to output an inhomogeneous struct to
stdout without using a loop to output each array contained in the struct.

cheers.

Rick C. Petty schrieb am 2009-06-30:
 On Tue, Jun 30, 2009 at 08:03:21PM +0200, Alexander Best wrote:
  should be stdout.


  struct Header *hdr = rom;

  int new_fd = open(/dev/stdout, O_RDWR);
  printf(SIZE: %d\n,sizeof(*hdr));
  write(new_fd, hdr, sizeof(*hdr));
  close(new_fd);

 Why are you reopening stdout?  It should already be open, so use
 fileno(stdout) or just plain STDOUT_FILENO instead of new_fd.

 -- Rick C. Petty
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Rick C. Petty
On Tue, Jun 30, 2009 at 08:21:03PM +0200, Alexander Best wrote:
 thanks. now the output gets redirected using . i'm quite new to programming
 under unix. sorry for the inconvenience.

No problem; we all had to learn sometime.  But what I suggested should
work for every platform that adheres to POSIX.  If you were using
fprintf/fwrite, then it would work on anything that's standard C.  As for
redirection, windows command line allows the same type of redirection.

 so i guess there is no really easy way to output an inhomogeneous struct to
 stdout without using a loop to output each array contained in the struct.

That's not something C would ever provide easily.  You may want to use a
different high-level language.  However, I often use macros for printing
pieces of structures, for example I used this to print out sizes of kernel
structures:

#define SIZE(astruct, member) \
printf(%d\t\t.%s\n, sizeof(astruct.member), #member)

#include sys/ktrace.h
...
struct ktr_header header;
struct ktr_genio genio;

printf(%d\tktr_header:\n, sizeof(header));
SIZE(header, ktr_len);
SIZE(header, ktr_type);
SIZE(header, ktr_pid);
SIZE(header, ktr_comm);
SIZE(header, ktr_time);
SIZE(header, ktr_time.tv_sec);
SIZE(header, ktr_time.tv_sec);
SIZE(header, ktr_tid);

printf(\n%d\tktr_genio:\n, sizeof(genio));
SIZE(genio, ktr_fd);
SIZE(genio, ktr_rw);

In your case, you could make a macro for each type.  Without an example of
how you want the output to look, it's hard for us to show you code that
will produce such output.

-- Rick C. Petty
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org


Re: c question: *printf'ing arrays

2009-06-30 Thread Alfred Perlstein
Hey Alex,

People frown on macros, but this could be a good one:

#define SPRINT(f, fmt) \
do {\
for (_i = 0; _i  sizeof(f)/sizeof(f[0]); i++) \
printf(fmt, f[i]); \
}while(0)

:D

This should allow you to point to any _array_ and print each
element of it using format fmt.

Example:
SPRINT(Header-game_title, %c);



-Alfred


* Alexander Best alexbes...@math.uni-muenster.de [090630 15:06] wrote:
 thanks for all the help. i decided to take the pill and coded all the fprintfs
 by hand. here's the result. usually i'd stick to a higher level languag, but i
 need C's inline assembly support:
 
 struct Header
 {
 u_int8_t rom_entry[4];
 u_int8_t nintendo_logo[156];
 u_char game_title[12];
 u_char game_code[4];
 u_char maker_code[2];
 u_int8_t fixed_val;
 u_int8_t unit_code;
 u_int8_t device_type;
 u_int8_t reserved_area1[7];
 u_int8_t software_version;
 u_int8_t complement_check;
 u_int8_t reserved_area2;
 u_int8_t ram_entry[4];
 u_int8_t boot_mode;
 u_int8_t slave_id;
 u_int8_t unused_area[26];
 u_int8_t joybus_entry[4];
 };
 
 struct Header * hdr = rom;
 int i;
 
 fprintf(stderr, ROM Entry: 0x);
 for (i=0; i  4; i++) fprintf(stderr, %x, hdr-rom_entry[i]);
 fprintf(stderr, \nNintendo Logo: 0x);
 for (i=0; i  sizeof(hdr-nintendo_logo); i++) fprintf(stderr, %x,
 hdr-nintendo_logo[i]);
 fprintf(stderr, \nGame Title: %s,  hdr-game_title);
 fprintf(stderr, \nGame Code: %s,  hdr-game_code);
 fprintf(stderr, \nMaker Code: %s,  hdr-maker_code);
 fprintf(stderr, \nFixed Value: 0x);
 fprintf(stderr, %x, hdr-fixed_val);
 fprintf(stderr, \nUnit Code: 0x);
 fprintf(stderr, %x, hdr-unit_code);
 fprintf(stderr, \nDevice Type: 0x);
 fprintf(stderr, %x, hdr-device_type);
 fprintf(stderr, \nReserved Area: 0x);
 for (i=0; i  sizeof(hdr-reserved_area1); i++) fprintf(stderr, %x,
 hdr-reserved_area1[i]);
 fprintf(stderr, \nSoftware Version: 0x);
 fprintf(stderr, %x, hdr-software_version);
 fprintf(stderr, \nComplement Check: 0x);
 fprintf(stderr, %x, hdr-complement_check);
 fprintf(stderr, \nReserved Area: 0x);
 fprintf(stderr, %x, hdr-reserved_area2);
 fprintf(stderr, \nRAM Entry Point: 0x);
 for (i=0; i  sizeof(hdr-ram_entry); i++) fprintf(stderr, %x,
 hdr-ram_entry[i]);
 fprintf(stderr, \nBoot Mode: 0x);
 fprintf(stderr, %x, hdr-boot_mode);
 fprintf(stderr, \nSlave ID: 0x);
 fprintf(stderr, %x, hdr-slave_id);
 fprintf(stderr, \nUnused Area: 0x);
 for (i=0; i  sizeof(hdr-unused_area); i++) fprintf(stderr, %x,
 hdr-unused_area[i]);
 fprintf(stderr, \nJoybus Entry Point: 0x);
 for (i=0; i  sizeof(hdr-joybus_entry); i++) fprintf(stderr, %x,
 hdr-joybus_entry[i]);
 
 cheers.
 
 Rick C. Petty schrieb am 2009-06-30:
  On Tue, Jun 30, 2009 at 08:21:03PM +0200, Alexander Best wrote:
   thanks. now the output gets redirected using . i'm quite new to
   programming
   under unix. sorry for the inconvenience.
 
  No problem; we all had to learn sometime.  But what I suggested
  should
  work for every platform that adheres to POSIX.  If you were using
  fprintf/fwrite, then it would work on anything that's standard C.  As
  for
  redirection, windows command line allows the same type of
  redirection.
 
   so i guess there is no really easy way to output an inhomogeneous
   struct to
   stdout without using a loop to output each array contained in the
   struct.
 
  That's not something C would ever provide easily.  You may want to
  use a
  different high-level language.  However, I often use macros for
  printing
  pieces of structures, for example I used this to print out sizes of
  kernel
  structures:
 
  #define SIZE(astruct, member) \
  printf(%d\t\t.%s\n, sizeof(astruct.member), #member)
 
  #include sys/ktrace.h
  ...
  struct ktr_header header;
  struct ktr_genio genio;
 
  printf(%d\tktr_header:\n, sizeof(header));
  SIZE(header, ktr_len);
  SIZE(header, ktr_type);
  SIZE(header, ktr_pid);
  SIZE(header, ktr_comm);
  SIZE(header, ktr_time);
  SIZE(header, ktr_time.tv_sec);
  SIZE(header, ktr_time.tv_sec);
  SIZE(header, ktr_tid);
 
  printf(\n%d\tktr_genio:\n, sizeof(genio));
  SIZE(genio, ktr_fd);
  SIZE(genio, ktr_rw);
 
  In your case, you could make a macro for each type.  Without an
  example of
  how you want the output to look, it's hard for us to show you code
  that
  will produce such output.
 
  -- Rick C. Petty
 ___
 freebsd-hackers@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
 To unsubscribe, send any mail to freebsd-hackers-unsubscr...@freebsd.org

-- 
- 

Re: c question: *printf'ing arrays

2009-06-30 Thread Alexander Best
wow. thanks. that's looking really nice. i'll change my sources tomorrow after
a good dose of sleep. ;)

alex

Alfred Perlstein schrieb am 2009-07-01:
 Hey Alex,

 People frown on macros, but this could be a good one:

 #define SPRINT(f, fmt) \
 do {\
 for (_i = 0; _i  sizeof(f)/sizeof(f[0]); i++) \
 printf(fmt, f[i]); \
 }while(0)

 :D

 This should allow you to point to any _array_ and print each
 element of it using format fmt.

 Example:
 SPRINT(Header-game_title, %c);



 -Alfred


 * Alexander Best alexbes...@math.uni-muenster.de [090630 15:06]
   wrote:
  thanks for all the help. i decided to take the pill and coded all
  the fprintfs
  by hand. here's the result. usually i'd stick to a higher level
  languag, but i
  need C's inline assembly support:

  struct Header
  {
  u_int8_t rom_entry[4];
  u_int8_t nintendo_logo[156];
  u_char game_title[12];
  u_char game_code[4];
  u_char maker_code[2];
  u_int8_t fixed_val;
  u_int8_t unit_code;
  u_int8_t device_type;
  u_int8_t reserved_area1[7];
  u_int8_t software_version;
  u_int8_t complement_check;
  u_int8_t reserved_area2;
  u_int8_t ram_entry[4];
  u_int8_t boot_mode;
  u_int8_t slave_id;
  u_int8_t unused_area[26];
  u_int8_t joybus_entry[4];
  };

  struct Header * hdr = rom;
  int i;

  fprintf(stderr, ROM Entry: 0x);
  for (i=0; i  4; i++) fprintf(stderr, %x, hdr-rom_entry[i]);
  fprintf(stderr, \nNintendo Logo: 0x);
  for (i=0; i  sizeof(hdr-nintendo_logo); i++) fprintf(stderr,
  %x,
  hdr-nintendo_logo[i]);
  fprintf(stderr, \nGame Title: %s,  hdr-game_title);
  fprintf(stderr, \nGame Code: %s,  hdr-game_code);
  fprintf(stderr, \nMaker Code: %s,  hdr-maker_code);
  fprintf(stderr, \nFixed Value: 0x);
  fprintf(stderr, %x, hdr-fixed_val);
  fprintf(stderr, \nUnit Code: 0x);
  fprintf(stderr, %x, hdr-unit_code);
  fprintf(stderr, \nDevice Type: 0x);
  fprintf(stderr, %x, hdr-device_type);
  fprintf(stderr, \nReserved Area: 0x);
  for (i=0; i  sizeof(hdr-reserved_area1); i++) fprintf(stderr,
  %x,
  hdr-reserved_area1[i]);
  fprintf(stderr, \nSoftware Version: 0x);
  fprintf(stderr, %x, hdr-software_version);
  fprintf(stderr, \nComplement Check: 0x);
  fprintf(stderr, %x, hdr-complement_check);
  fprintf(stderr, \nReserved Area: 0x);
  fprintf(stderr, %x, hdr-reserved_area2);
  fprintf(stderr, \nRAM Entry Point: 0x);
  for (i=0; i  sizeof(hdr-ram_entry); i++) fprintf(stderr,
  %x,
  hdr-ram_entry[i]);
  fprintf(stderr, \nBoot Mode: 0x);
  fprintf(stderr, %x, hdr-boot_mode);
  fprintf(stderr, \nSlave ID: 0x);
  fprintf(stderr, %x, hdr-slave_id);
  fprintf(stderr, \nUnused Area: 0x);
  for (i=0; i  sizeof(hdr-unused_area); i++) fprintf(stderr,
  %x,
  hdr-unused_area[i]);
  fprintf(stderr, \nJoybus Entry Point: 0x);
  for (i=0; i  sizeof(hdr-joybus_entry); i++) fprintf(stderr,
  %x,
  hdr-joybus_entry[i]);

  cheers.

  Rick C. Petty schrieb am 2009-06-30:
   On Tue, Jun 30, 2009 at 08:21:03PM +0200, Alexander Best wrote:
thanks. now the output gets redirected using . i'm quite new
to
programming
under unix. sorry for the inconvenience.

   No problem; we all had to learn sometime.  But what I suggested
   should
   work for every platform that adheres to POSIX.  If you were using
   fprintf/fwrite, then it would work on anything that's standard C.
   As
   for
   redirection, windows command line allows the same type of
   redirection.

so i guess there is no really easy way to output an
inhomogeneous
struct to
stdout without using a loop to output each array contained in
the
struct.

   That's not something C would ever provide easily.  You may want
   to
   use a
   different high-level language.  However, I often use macros for
   printing
   pieces of structures, for example I used this to print out sizes
   of
   kernel
   structures:

   #define SIZE(astruct, member) \
   printf(%d\t\t.%s\n, sizeof(astruct.member), #member)

   #include sys/ktrace.h
   ...
   struct ktr_header header;
   struct ktr_genio genio;

   printf(%d\tktr_header:\n, sizeof(header));
   SIZE(header, ktr_len);
   SIZE(header, ktr_type);
   SIZE(header, ktr_pid);
   SIZE(header, ktr_comm);
   SIZE(header, ktr_time);
   SIZE(header, ktr_time.tv_sec);
   SIZE(header, ktr_time.tv_sec);
   SIZE(header, ktr_tid);

   printf(\n%d\tktr_genio:\n, sizeof(genio));
   SIZE(genio, ktr_fd);
   SIZE(genio, ktr_rw);

   In your case, you could make a macro for each type.  Without an
   example of
   how you want the output to look, it's hard for us to 

Re: Port-related C++ question

2001-04-29 Thread Dima Dorfman

Jos Backus [EMAIL PROTECTED] writes:
 On Sat, Apr 28, 2001 at 09:32:51PM -0700, Dima Dorfman wrote:
  Jos Backus [EMAIL PROTECTED] writes:
 void  stdin(const Config config);  -=== line 99
  
  `stdin' is a global variable which, surprisingly enough, refers to the
  standard input stream.  Don't name a function after it and your
  problem should go away.
 
 Yeah, I am just puzzled as to how this can build at all on other platforms
 (Linux?), unless they don't define this variable.

I don't know how other systems do it, but I can imagine that they
could define `stdin' as a real global variable--as compared to a
#define in FreeBSD.  Then the above just spams over the symbol.  I
don't know the details of C's scoping rules to know if that would work
as they want it, but I guess it's possible.

 
 Thanks,
 -- 
 Jos Backus _/  _/_/_/Modularity is not a hack.
   _/  _/   _/-- D. J. Bernstein
  _/  _/_/_/ 
 _/  _/  _/_/
 [EMAIL PROTECTED] _/_/   _/_/_/use Std::Disclaimer;
 
 To Unsubscribe: send mail to [EMAIL PROTECTED]
 with unsubscribe freebsd-hackers in the body of the message
 

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message



Re: Port-related C++ question

2001-04-29 Thread Peter Seebach

In message [EMAIL PROTECTED], Jos Backus writes:
Yeah, I am just puzzled as to how this can build at all on other platforms
(Linux?), unless they don't define this variable.

Many of them probably have it as an external object, not a #define.  I'm
still not sure the code makes any sense.

-s

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message



Re: Port-related C++ question

2001-04-29 Thread Warner Losh

In message [EMAIL PROTECTED] Peter Seebach writes:
: In message [EMAIL PROTECTED], Jos Backus writes:
: Yeah, I am just puzzled as to how this can build at all on other platforms
: (Linux?), unless they don't define this variable.
: 
: Many of them probably have it as an external object, not a #define.  I'm
: still not sure the code makes any sense.

The standards allow for it to be a #define (just like they allow errno 
to be a #define), so code that uses like the code that was posted
earlier is not strictly conforming.

Warner

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message



Port-related C++ question

2001-04-28 Thread Jos Backus

[Apologies if this is the wrong list for this type of question.]

I am trying to create a port for a commandline-accessible database tool, but I
am running into the following problem (on RELENG_4 as of today):

===  Building for dbtool-1.3
c++ -DPACKAGE=\dbtool\ -DVERSION=\1.3\ -DSTDC_HEADERS=1 -DHAVE_UNISTD_H=1 
-DHAVE_STDIO_H=1 -DHAVE_STDLIB_H=1 -DHAVE_LIBPCRE=1 -DHAVE_GETOPT=1 -DHAVE_FDOPEN=1 
-DHAVE_FGETC=1 -DHAVE_GETENV=1 -DHAVE_BERKELEY=1  -I. -I.-I/usr/local/include/db3  
-Wall -Wstrict-prototypes -O2 -c cmd.cc
In file included from cmd.cc:22:
dbtool.h:99: declaration of `__sF' as array of references
gmake: *** [cmd.o] Error 1
*** Error code 2

/*
 * The Engine class will do all gdbm related stuff, i.e.
 * insert, search, create, remove and so on.
 * methods defined in engine.cc
 */
class Engine {
 private:
  void init(const Config config); /* init() will be called from every member once */

#ifdef HAVE_BERKELEY
  Db *db;
#else
  GDBM_FILE db;
#endif

  string pkg;

 public:
  Engine() {;;};
  void insert(const Config config);
  void update(const Config config);
  void remove(const Config config);
  void select(const Config config);
  void  stdin(const Config config);  -=== line 99
  void   dump(const Config config);
  void regexp(const Config config);
};

Anyone have any ideas on how to fix this?

Thanks,
-- 
Jos Backus _/  _/_/_/Modularity is not a hack.
  _/  _/   _/-- D. J. Bernstein
 _/  _/_/_/ 
_/  _/  _/_/
[EMAIL PROTECTED] _/_/   _/_/_/use Std::Disclaimer;

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message



Re: Port-related C++ question

2001-04-28 Thread Dima Dorfman

Jos Backus [EMAIL PROTECTED] writes:
   void  stdin(const Config config);  -=== line 99

`stdin' is a global variable which, surprisingly enough, refers to the
standard input stream.  Don't name a function after it and your
problem should go away.

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message



Re: Port-related C++ question

2001-04-28 Thread Warner Losh

In message [EMAIL PROTECTED] Jos Backus writes:
: dbtool.h:99: declaration of `__sF' as array of references
:   void  stdin(const Config config);  -=== line 99

stdin is #defined to be __sF[0].

Warner

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message



Re: Port-related C++ question

2001-04-28 Thread Jos Backus

On Sat, Apr 28, 2001 at 09:32:51PM -0700, Dima Dorfman wrote:
 Jos Backus [EMAIL PROTECTED] writes:
void  stdin(const Config config);  -=== line 99
 
 `stdin' is a global variable which, surprisingly enough, refers to the
 standard input stream.  Don't name a function after it and your
 problem should go away.

Yeah, I am just puzzled as to how this can build at all on other platforms
(Linux?), unless they don't define this variable.

Thanks,
-- 
Jos Backus _/  _/_/_/Modularity is not a hack.
  _/  _/   _/-- D. J. Bernstein
 _/  _/_/_/ 
_/  _/  _/_/
[EMAIL PROTECTED] _/_/   _/_/_/use Std::Disclaimer;

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-hackers in the body of the message



Re: X11/C++ question

1999-11-03 Thread Warner Losh

In message [EMAIL PROTECTED] Chuck Robey 
writes:
: Does anyone (anyone, that is, who's coded X11 applications) know how you
: handle X11 callbacks to C++ object methods?

OI_add_event(3OI) :-)

Warner


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-11-03 Thread Chuck Robey

On Wed, 3 Nov 1999, Warner Losh wrote:

 In message [EMAIL PROTECTED] Chuck Robey 
writes:
 : Does anyone (anyone, that is, who's coded X11 applications) know how you
 : handle X11 callbacks to C++ object methods?
 
 OI_add_event(3OI) :-)

Uhhh?  I've long since got the answer I wanted, but this seems a complete
mystery, so I'll bite, what's a OI_add_event?  From some package?  Can't
find a man page on it.

 
 Warner
 


Chuck Robey| Interests include C programming, Electronics,
213 Lakeside Dr. Apt. T-1  | communications, and signal processing.
Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and
(301) 220-2114 |   jaunt.mat.net : FreeBSD-current(Alpha)




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-11-03 Thread Warner Losh

In message [EMAIL PROTECTED] Chuck Robey writes:
: Uhhh?  I've long since got the answer I wanted, but this seems a complete
: mystery, so I'll bite, what's a OI_add_event?  From some package?  Can't
: find a man page on it.

OI was a native C++ toolkit that had a nice interface and was ported
to Linux and FreeBSD back in 1993 or so by yours truly.  It was
available from ParcPlace.  Sadly, it never went anywhere and all
efforts of the engineers to make it open sourced (this was in 1996)
failed.  It was ment as a joke for the long timers on the list...

Warner



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-11-03 Thread Thomas David Rivers

 
 In message [EMAIL PROTECTED] Chuck Robey 
writes:
 : Uhhh?  I've long since got the answer I wanted, but this seems a complete
 : mystery, so I'll bite, what's a OI_add_event?  From some package?  Can't
 : find a man page on it.
 
 OI was a native C++ toolkit that had a nice interface and was ported
 to Linux and FreeBSD back in 1993 or so by yours truly.  It was
 available from ParcPlace.  Sadly, it never went anywhere and all
 efforts of the engineers to make it open sourced (this was in 1996)
 failed.  It was ment as a joke for the long timers on the list...
 
 Warner
 
 
 
 To Unsubscribe: send mail to [EMAIL PROTECTED]
 with "unsubscribe freebsd-hackers" in the body of the message
 

 Let me add that as a stock holder of ParcPlace (now ObjectShare)
 and one of the people who tried out OI - I was disappointed it
 didn't go anywhere.  It seemed nice... (I wonder where it is now?)

 ObjectShare is trading right now at 44-cents/share - an amazing 18.92% 
 increase so far for the day (up 7 cents).  Perhaps that outstanding 
 stock price reflects the outcome of some of their decisions?  [I believe 
 my last purchase of ObjectShare was somewhere in the $10 range... sigh.]


- Dave Rivers -


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-27 Thread Alexey Zelkin

hi,

 Does anyone (anyone, that is, who's coded X11 applications) know how you
 handle X11 callbacks to C++ object methods?
 
 Thanks,

 TDR  If you mean Xt (and possibly Motif) - the answer is "very carefully."

 TDR  The Xt callbacks are C based, so you typically can't directly call a 
 TDR  C++ method.

 TDR  But, you can have an extern "C" block that declares the call back
 TDR  function (the extern "C" basically keeps any name mangling from going on)
 TDR  and then, in that function, invoke the method as appropriate.

 TDR  I believe you do something like:

 TDR   class myclass {
 TDR   void mymethod(void * arg1) {
 TDR   cout  "Ha! I got to the class"  '\n';
 TDR   };
 TDR   }

 TDR   extern "C" {

 TDR  void
 TDR  callback_function(arg1)
 TDR  void *arg1;
 TDR  {
 TDR /* Call the method */
 TDR  myclass::mymethod(arg1);
 TDR  }

 TDR   }

Looks good except one point -- mymethod should be static, i.e.

static void mymethod (...) {
  ...
}

 TDR Then, you register "callback_function" as the Xt/Motif callback.

 TDR I've at least "heard" of doing that kind of thing before...

-- 
/* Alexey Zelkin[EMAIL PROTECTED]*/
/* Tavric National University   [EMAIL PROTECTED]  */
/* http://www.ccssu.crimea.ua/~phantom  [EMAIL PROTECTED] */


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-27 Thread Ville-Pertti Keinonen

[EMAIL PROTECTED] (Chuck Robey) writes:

 Boy, I sure wish Java compiled and ran natively.  I'd stop using C++
 forever.

gcc-2.95.1 + libgcj already works, at least for simple programs.  On
FreeBSD 3.x programs seem to work as long as you use statically linked
libraries (shared libraries cause the garbage collector to dump core).

There already seems to be some awt code in libgcj, I have no idea
whether it's actually functional.

And the speed isn't quite comparable to what you can achieve
lower-level languages (pretty close to the equivalent C++ code with
all methods virtual, heavy use of rtti and common-base-class-based
containers), but probably good enough for a lot of things.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-27 Thread Wes Peters

Chuck Robey wrote:
 
 On Tue, 26 Oct 1999 [EMAIL PROTECTED] wrote:
 
 
  Thomas David Rivers writes:
 If you mean Xt (and possibly Motif) - the answer is "very carefully."
  [...]
 
  You're approach would probably work, but there's an easier way.
  See topic 28 in the Xt FAQ.
 
  ftp://ftp.x.org/contrib/faqs/FAQ-Xt
 
  It's not name mangling causing problems, it's lack of "this" when the
  method is invoked as a callback from Xt.
 
 Yes!  This is the method!  I like it, or at least, it's as close (in C++
 code) to something I do like.

I assume they're using a static member function for the callback and storing
the this pointer for the object somewhere handy?  This is the canonical way
to re-enter C++ code from C land, and can even be used for C++ interrupt
handlers if you're very careful.

-- 
"Where am I, and what am I doing in this handbasket?"

Wes Peters Softweyr LLC
[EMAIL PROTECTED]   http://softweyr.com/


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-27 Thread Chuck Robey

On Wed, 27 Oct 1999, Wes Peters wrote:

 Chuck Robey wrote:
  
  On Tue, 26 Oct 1999 [EMAIL PROTECTED] wrote:
  
  
   Thomas David Rivers writes:
  If you mean Xt (and possibly Motif) - the answer is "very carefully."
   [...]
  
   You're approach would probably work, but there's an easier way.
   See topic 28 in the Xt FAQ.
  
   ftp://ftp.x.org/contrib/faqs/FAQ-Xt
  
   It's not name mangling causing problems, it's lack of "this" when the
   method is invoked as a callback from Xt.
  
  Yes!  This is the method!  I like it, or at least, it's as close (in C++
  code) to something I do like.
 
 I assume they're using a static member function for the callback and storing
 the this pointer for the object somewhere handy?  This is the canonical way
 to re-enter C++ code from C land, and can even be used for C++ interrupt
 handlers if you're very careful.

Yes, you store the address of the object you want the callback vectored to
in the UserData Xt pointer, and when the callback comes into the static
func, it just takes the offered object address and reflects the call back
out to the right function in the right object.  Neat, the user never sees
any complication at all.

 
 


Chuck Robey| Interests include C programming, Electronics,
213 Lakeside Dr. Apt. T-1  | communications, and signal processing.
Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and
(301) 220-2114 |   jaunt.mat.net : FreeBSD-current(Alpha)




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



X11/C++ question

1999-10-26 Thread Chuck Robey

Does anyone (anyone, that is, who's coded X11 applications) know how you
handle X11 callbacks to C++ object methods?

Thanks,


Chuck Robey| Interests include C programming, Electronics,
213 Lakeside Dr. Apt. T-1  | communications, and signal processing.
Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and
(301) 220-2114 |   jaunt.mat.net : FreeBSD-current(Alpha)




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Thomas David Rivers

 
 Does anyone (anyone, that is, who's coded X11 applications) know how you
 handle X11 callbacks to C++ object methods?
 
 Thanks,

 If you mean Xt (and possibly Motif) - the answer is "very carefully."

 The Xt callbacks are C based, so you typically can't directly call a 
 C++ method.

 But, you can have an extern "C" block that declares the call back
 function (the extern "C" basically keeps any name mangling from going on)
 and then, in that function, invoke the method as appropriate.

 I believe you do something like:

  class myclass {
void mymethod(void * arg1) {
cout  "Ha! I got to the class"  '\n';
};
  }


  extern "C" {

 void
 callback_function(arg1)
 void *arg1;
 {
  /* Call the method */
   myclass::mymethod(arg1);
 }


  }


Then, you register "callback_function" as the Xt/Motif callback.

I've at least "heard" of doing that kind of thing before...

- Dave Rivers -



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Daniel O'Connor


On 27-Oct-99 Thomas David Rivers wrote:
   If you mean Xt (and possibly Motif) - the answer is "very carefully."

Or you could just use a toolkit written for C++ or with C++ shims already.. ie
Qt or GTK..

---
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
  -- Andrew Tanenbaum


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Daniel O'Connor


On 27-Oct-99 Thomas David Rivers wrote:
  And, wasn't there a freely available C++ shim for motif floating around
  at one time?

I don't know.. My X experience begins and ends with Tk :)
(Don't like Motif either ;)

---
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
  -- Andrew Tanenbaum


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Chris Costello

On Tue, Oct 26, 1999, Thomas David Rivers wrote:
   extern "C" {
 
  void
  callback_function(arg1)
  void *arg1;
  {
 /* Call the method */
  myclass::mymethod(arg1);

   As far as I've seen, you can't directly call a class method
without an object.

-- 
|Chris Costello [EMAIL PROTECTED]
|A closed mouth gathers no feet.
`--


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread tbuswell


Thomas David Rivers writes:
   If you mean Xt (and possibly Motif) - the answer is "very carefully."
[...]

You're approach would probably work, but there's an easier way.
See topic 28 in the Xt FAQ.

ftp://ftp.x.org/contrib/faqs/FAQ-Xt

It's not name mangling causing problems, it's lack of "this" when the
method is invoked as a callback from Xt.

-Ted


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Chuck Robey

On Tue, 26 Oct 1999, Thomas David Rivers wrote:

  
  Does anyone (anyone, that is, who's coded X11 applications) know how you
  handle X11 callbacks to C++ object methods?
  
  Thanks,
 
  If you mean Xt (and possibly Motif) - the answer is "very carefully."
 
  The Xt callbacks are C based, so you typically can't directly call a 
  C++ method.
 
  But, you can have an extern "C" block that declares the call back
  function (the extern "C" basically keeps any name mangling from going on)
  and then, in that function, invoke the method as appropriate.
 
  I believe you do something like:

[example deleted]

Then you just stick a C wrapper function around every C++ callback you
want to register, is that it?  Seems a bit inelegant, but I suppose, if
the ultimate test of elegance is that "it's the only one that works", then
it's perhaps elegant *enough*.


Chuck Robey| Interests include C programming, Electronics,
213 Lakeside Dr. Apt. T-1  | communications, and signal processing.
Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and
(301) 220-2114 |   jaunt.mat.net : FreeBSD-current(Alpha)




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Chuck Robey

On Wed, 27 Oct 1999, Daniel O'Connor wrote:

 
 On 27-Oct-99 Thomas David Rivers wrote:
If you mean Xt (and possibly Motif) - the answer is "very carefully."
 
 Or you could just use a toolkit written for C++ or with C++ shims already.. ie
 Qt or GTK..

If I wanted to just get X11 done, I would just call some toolkit.  I
didn't want to be told to go get something else that does it, I wanted to
know the right way to do it myself.

Thomas's post, at least, was really helpful.  I wonder if that's really
the way to go, but he surely did give me *one* method, and explained it
easily enough so that I can *do* it.

Boy, I sure wish Java compiled and ran natively.  I'd stop using C++
forever.



Chuck Robey| Interests include C programming, Electronics,
213 Lakeside Dr. Apt. T-1  | communications, and signal processing.
Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and
(301) 220-2114 |   jaunt.mat.net : FreeBSD-current(Alpha)




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Thomas David Rivers

 Then you just stick a C wrapper function around every C++ callback you
 want to register, is that it?  Seems a bit inelegant, but I suppose, if
 the ultimate test of elegance is that "it's the only one that works", then
 it's perhaps elegant *enough*.

  I believe someone posted a better solution... from the Xt FAQ.

- Dave R. -




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Chuck Robey

On Tue, 26 Oct 1999 [EMAIL PROTECTED] wrote:

 
 Thomas David Rivers writes:
If you mean Xt (and possibly Motif) - the answer is "very carefully."
 [...]
 
 You're approach would probably work, but there's an easier way.
 See topic 28 in the Xt FAQ.
 
 ftp://ftp.x.org/contrib/faqs/FAQ-Xt
 
 It's not name mangling causing problems, it's lack of "this" when the
 method is invoked as a callback from Xt.

Yes!  This is the method!  I like it, or at least, it's as close (in C++
code) to something I do like.

Thanks very much, Ted.  Nice catch.

 
 -Ted
 


Chuck Robey| Interests include C programming, Electronics,
213 Lakeside Dr. Apt. T-1  | communications, and signal processing.
Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and
(301) 220-2114 |   jaunt.mat.net : FreeBSD-current(Alpha)




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Bakul Shah

Allow me add something to what the FAQ-Xt says.

I find it more convenient to immediately call a non-static
function as shown below (using a slightly modified example
from the FAQ).

class Icon {
public:
Icon(Widget*);
private:
static void static_callback(Icon*);
inline void real_callback();
Widget* button;
int count;
...
};

Icon::Icon(Widget* parent): count(0)
{
button = XtVaCreateWidget("Boo!", xmPushButtonWidgetClass, parent, 0);
XtAddCallback(button,  XmNselectCallback, Icon::static_callback,
  (XtPointer)this);
...
}

inline void
Icon::real_callback()
{
count++;
...
}

void
Icon::static_callback(Icon* icon)
{
icon-real_callback();
}

The reason for calling real_callback from static_callback is
to avoid having to specify icon-count etc. to reference
components of the Icon object.  This makes a difference in
readability if your callback function does a bunch of stuff.
The reason for inlining to not incur the cost of an
additional call (if this matters -- usually it doesn't).
Inlining can get in your way during debugging (atleast gdb
loses its mind) so provide a way to disable it.  BTW, this
idiom is useful pretty much any time you have to use C++
callbacks from C code, not just for X11.


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Chuck Robey

On Tue, 26 Oct 1999, Bakul Shah wrote:

 Allow me add something to what the FAQ-Xt says.
 
 I find it more convenient to immediately call a non-static
 function as shown below (using a slightly modified example
 from the FAQ).

Just got out of the shower, where I was wondering why they didn't suggest
the same thing.  I was going to experiment with this way, since it fit
more closely with the way I like to code C++ (I don't like to code C++,
you understand, so my C++ code is always straining to look like C).

Thanks, Bakul.  This looks much better.  Thanks, folks, for letting me
pull hackers away from FreeBSD for a minute, but let's not let it get out
of hand; we better stop before we strain other's patience.



Chuck Robey| Interests include C programming, Electronics,
213 Lakeside Dr. Apt. T-1  | communications, and signal processing.
Greenbelt, MD 20770| I run picnic.mat.net: FreeBSD-current(i386) and
(301) 220-2114 |   jaunt.mat.net : FreeBSD-current(Alpha)




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message



Re: X11/C++ question

1999-10-26 Thread Brian Fundakowski Feldman

On Tue, 26 Oct 1999, Chris Costello wrote:

 On Tue, Oct 26, 1999, Thomas David Rivers wrote:
extern "C" {
  
   void
   callback_function(arg1)
   void *arg1;
   {
/* Call the method */
 myclass::mymethod(arg1);
 
As far as I've seen, you can't directly call a class method
 without an object.

Sure you can.  It won't have any access to "this" or any part thereof,
however.

 
 -- 
 |Chris Costello [EMAIL PROTECTED]
 |A closed mouth gathers no feet.
 `--
 

-- 
 Brian Fundakowski Feldman   \  FreeBSD: The Power to Serve!  /
 [EMAIL PROTECTED]`--'



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message