www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/05/03:35:13

From: G DOT DegliEsposti AT ads DOT it
To: djgpp AT delorie DOT com
Message-ID: <C12565A2.002E3B6E.00@vega.ads.it>
Date: Thu, 5 Feb 1998 09:33:42 +0100
Subject: Re: Sizeof and pointers
Mime-Version: 1.0




>void func(unsigned char *tmp)
>{
>// BLAH BLAH
>}
>
>How do i find how many bytes tmp is taking up in memory:
>
>the sizeof funtion returns 4 bytes, the reason being (i think) that it
>is finding out how many bytes the pointer takes up in memory. I dont
>want to use strlen(tmp) because the string may have a '\0' character.

Not easy... in C strings do not exist (as language constructs): they are
defined in a conventional way within the libraries.

"char * tmp" actually means "the address of a data of type character" and
*we* know wether the following addresses contain valid data or not but
the compiler doesn't.

This means there's no way that the compiler can know how many valid
characters follow the one pointed by tmp. You have to tell.

The fastest way is to add an argument to the function specifying how
many valid chararcters tmp takes...

void func(int len, unsigned char * tmp)
{
// ...
}

ciao
  Giacomo



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019