[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] pointer gymnastik



Hejsa,
egentlig har problemet været løst siden sent fredag aften, ved indlægget
af Jesper Monsted, men (mest) nedenstående vil da give samme resultat,
omend med et noget større forbrug af CPU'ens tid, men det vil ikke være
signifikant ved korte strenge. På den anden side set, spilder man
CPU-tid i alle sammenhænge, må vi snart kræve 1 GHz CPU'er med 1 ns
RAM-accestid (n=nano, 10^-9). 

Enhver fornuftig compiler BØR sandelig lade en streng være en
sammenhængende streng og hvis Java ikke gør det, bekræfter det bare min
tidligere udefinerede skepsis mod samme.

Problemet løses ved at sammenskrive et par af de fungerende eksempler:

int lookupChar( const char *str, char c )
   {
   return( str-strchr( str, c ) )
   }

..... men det er der vel dårligt behov for at lave en seperat funktion
til.

Med venlig hilsen
Søren H. Sørensen

[Computer-Dinosaur, and HAM, Radio Amateur, call: OZ1SO, Cept Cat. 1]

Per Vognsen wrote:
> 
> Kim Pedersen wrote:
> <snip>
> > >int lookupChar(const char *str, char c)
> > >{
> > >  char *p;
> > >  int i;
> > >
> > >  for (p = str, i = 0; *p != '\0'; *p++, i++)
> > >  {
> > >    if (*p == c)
> > >      return i;
> > >  }
> > >
> > >  return -1;
> > >}
> >
> >   assignmenten: *p++ virker kun på grund af at hvad du har puttet ind i den
> > pointer to char incrementerer liniært, men vil ikke virke på alle
> > compilers, at sige p++ derimod vil incrementere p til den næste hukummelses
> > adresse af den type den er allocated til. Se måske "The C++ Programming
> > language" omkring det. Det virker men er ikke tilrådeligt.
> 
> Argh, jeg vidste at nogen ville se det. Jeg burde have puttet den
> obligatoriske disclaimer i bunden af denne besked; mailer code, du ved
> nok. Ja, jeg saa ogsaa dette lige efter at jeg havde sendt den, men
> syntes ikke at det var noedvendigt med en rettelse da jeg regner med at
> folkene paa listen ved hvad de laver.
> 
> >   Med Venlig Hilsen
> >   Kim Pedersen
> 
> --
> | Per Vognsen (Randers - Denmark)| "Superstition is a  word the |
> | Mail: <sslug@sslug>   | ignorant  use   to  describe |
> | Voice: +45 20639009            | their own ignorance." - Sifu |


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *