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

From: gtippery (gtippery_at_altavista.net)
Date: 03/12/05


Date: 12 Mar 2005 02:30:13 -0800


Mark F. Haigh wrote:
> 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.

The "real app" is mentioned in the original post (in a comment).
Anyway, I wasn't objecting, just explaining.

> 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.

Well, "de gustibus non est disputandum", and I've no reason to think
mine's particularly good. The compiler choice is partially dictated by
the target system, which runs PC-DOS 6. I've also got Borland's
compiler, but it seemed like overkill. PowerC, as far as I've seen to
date, has all the C89 features except localization (if that's strictly
C89). It may not be "picky" enough -- I need to check the options in
the docs.

>
...
> 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 learned this from an earlier post in this same thread, myself.

> 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).
>

Noted.

> 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.
>

The platform limit is 64KB for any one item (i8086). The array would
be the limiting factor in this case (at something over 5,000 elements),
but it's never going to get that big - the maximum dimension is 512.

If size_t isn't actually an int (of some standard type), isn't that
going to be a problem in the for()? I thought the index variable had
to be an integer or enumeration.

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

Thanks.



Relevant Pages

  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)
  • Re: cpu type idea
    ... compiler related recently. ... int main ... float a; ... just to parallelize the vectror and tensor operations. ...
    (alt.lang.asm)
  • Re: [CodeGallery] MFC MD5 Calculator
    ... Then when they added types, internally, the compiler still thought they were int values, ... ANSI standard began to emerge that the language design ...
    (microsoft.public.vc.mfc)