Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: Are bad developer libraries the problem with M$ software?

From: <cdavison(at)nucleus.com>
Date: Mon Nov 18 2002 - 12:55:31 EST


As a follow-up to my post, where I said: "I believe you mean strlen and not sizeof. sizeof(mystr) will return the same as sizeof(char*), which is sizeof(int) in most cases or 4 on 32-bit platforms. Unless there's something I wasn't aware of: you're using a bizarre compiler, or C++, or there's a special case for char arrays on the stack."

Looks like there's a special case for char arrays on the stack (which I guess technically would be of type char[] and not char*). Once you pass the string around to functions as a char*, or allocate it dynamically, you can't use sizeof.

#include <stdio.h>
void fn (char *p) {
  printf ("sizeof(p) = %d\n", sizeof(p));
}

int main () {
  char x[15];
  printf ("sizeof(x) = %d\n", sizeof(x));   fn (x);
  return 0;
}

Output:
sizeof(x) = 15
sizeof(p) = 4 Received on Mon Nov 18 19:59:33 2002

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:02:44 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library