Re: Please help optimize (and standarize) this code...

From: Mark F. Haigh (mfhaigh_at_sbcglobal.net)
Date: 03/12/05


Date: 11 Mar 2005 19:20:38 -0800

gtippery wrote:
> Mark F. Haigh wrote:
>

<large snip>

> If you just wanted to show something similar, that's fine, and it was
> interesting. But the reason I didn't use an array of strings in the
> first place is that in the real program, the data's coming from an
> existing packed data structure in memory (returned by the OS), and
> would have to be converted to strings to use your sentinel and
printing
> techniques; so as far as I can see I'd need the memcpy()'s anyway.

And how was I supposed to know this? State this up front next time.
I'd thought it was for some kind of class project (first name / 3 digit
telephone extension), and that you had poor taste in data structures
and compilers.

I'll take another look when I get some time. Disregard the previous
post, and note:

1. Yes, you should cast size_t to int if it's going to be going
through the default argument promotions. I shouldn't have posted so
hastily right before bedtime (on some days, my only time for c.l.c).
Shame on me.

2. There are all kinds of dirty tricks and pre-canned "divide by x"
code sequences for compiler writers. Look at "Hacker's Delight" by
Henry S. Warren Jr. for more info on some interesting tricks (magic
numbers, etc).

3. What's the biggest number of elements that your array can have?
Check your platform docs. It may be more than int can handle, but less
than or equal to what size_t can handle.

4. Always put a return statement in main. It's necessary in C89, and
good style in C99.

Mark F. Haigh
mfhaigh@sbcglobal.net



Relevant Pages

  • Returning char* / System.String array from unmanaged c++ dll into a c# application
    ... how can i return an array of strings from an unmanaged c++ dll into a c# ... Mark ...
    (microsoft.public.dotnet.languages.vc)
  • Re: K&R2 Secition 5.9 - major blunders
    ... Each element of b doesn't point to a 20 element array of int. ... This mistake is crucial because ... my explanation is really the qualities of something else: ... > The use of the array of pointers is to store the strings. ...
    (comp.lang.c)
  • Re: K&R2 Secition 5.9 - major blunders
    ... Each element of b doesn't point to a 20 element array of int. ... This mistake is crucial because ... my explanation is really the qualities of something else: ... > The use of the array of pointers is to store the strings. ...
    (comp.lang.c)
  • Re: Returning array of strings through callback from unmanaged to
    ... Is the array of strings a jagged array or fixed length array? ... It is imperative that I am able to return the array of strings from the ... I have control over how many strings I want the unmanaged code to return ... What I want to accomplish is to pass a callback function to unmanaged ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: attempting to return values from array from w/in a function
    ... What I get is an array w/ only the most recent array entry. ... I am new to PHP & do not have formal scripting ... you end up comparing strings, but the test you mean probably is simply: ... case 1: {codeblock} ...
    (comp.lang.php)