Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Find the size of pointer in C

Name: Anonymous 2009-06-25 0:32

suppose char *str has some bytes(not malloced), how can i determine the size of *str without access to str itself?

Name: Anonymous 2009-06-25 0:34

Pointers are all the same size in C

Name: Anonymous 2009-06-25 0:39

>>2
I know, i just want to to know how long the data in pointer is.
like "abc" is three bytes "a" is one but *str doesn't shows that unless it was malloc'ed.

Name: Anonymous 2009-06-25 0:43

sizeof?

Name: Anonymous 2009-06-25 0:45

>>4
sizeof work on datatypes(int,char,pointer address,etc), not byte strings.

Name: Anonymous 2009-06-25 0:50

~ >cat > test.c
#include <stdio.h>
int main()
{
    char * str = "abc";
    printf("%d\n",sizeof(str));
    return 0;
}
~ >gcc test.c
~ >./a.out
4
~ >

Name: Anonymous 2009-06-25 0:51

try with "asdahsdsahd\0abcdef"

Name: Anonymous 2009-06-25 0:52

>>6
I smirked.

Name: Anonymous 2009-06-25 1:12

>>7
did you even try >>6's code?

Name: Anonymous 2009-06-25 1:19

>>9
>>6 returns the size of pointer address

Name: Anonymous 2009-06-25 1:20

>>10
Address is a pointer lawl

Name: Anonymous 2009-06-25 1:21

Fucking retards. Gonna try googling it on obscure sepples forums.

Name: Anonymous 2009-06-25 1:25

Protip: you can't and you're an idiot who will never be a real programmer.

Name: >>6 2009-06-25 1:46

>>12
Successful trolling is successful. Don't forget to vote for me on www.ratemytroll.com

Name: Anonymous 2009-06-25 1:57

>>2
The standard does not guarantee that function pointers have the same size of data pointers.

Name: Anonymous 2009-06-25 2:20

>>15
Does it mention the rationale behind that decision? Seems odd to me.

Name: Anonymous 2009-06-25 2:24

>>16
Some architectures store code and data in separate address spaces.

Name: Anonymous 2009-06-25 2:38

>>15
the standard doesn't guarantee that float pointers and int pointers are the same size either.

Name: Anonymous 2009-06-25 3:27


int strlen(unsigned char *string_start)
{
   /* Initialize a unsigned char pointer here  */
   /* A loop that starts at string_start and
    * is increment by one until it's value is zero,
    *e.g. while(*s!=0) or just simply while(*s) */
   /* Return the difference of the incremented pointer and the original pointer */
}

Name: Anonymous 2009-06-25 4:30

>>19

int strlen(unsigned char *string_start)
{ return strrchr(string_start, 0) - string_start; }

Name: Anonymous 2009-06-25 4:35

>>20
actually, that should be:
size_t strlen(const char *string_start)
{ return (size_t)(strchr(string_start, 0) - string_start); }

Name: Anonymous 2009-06-25 4:51

>>19-21
how can i determine the size of *str without access to str itself?
Basically, he's asking the impossible.

Name: Anonymous 2009-06-25 5:00

>>22
>>19-21 doesn't have anything to do with what he was asking. that was already solved by >>6. we've moved on to more interesting things.

Name: Anonymous 2009-06-25 6:55

>>1
Look at where you declared *str

Name: Anonymous 2010-11-25 19:14

Name: Anonymous 2011-02-04 14:06

Don't change these.
Name: Email:
Entire Thread Thread List