Berkeley CSUA MOTD:Entry 35217
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2004/12/8-9 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages] UID:35217 Activity:kinda low
12/8    When people say null string or empty string in C, does it mean a char
        pointer that's NULL, or a char array whose first char is '\0'?  Thanks.
        \_ Both, because it's essentially the same. However, I think they
           probably mean the latter. I assume you mean a pointer pointing
           to NULL, and not a pointer which is NULL, which makes no real
           sense.
           \_ What's I'm thinking is that for "char *str", it can be either
              "str == NULL" or "str[0] == '\0'".  So you're saying that for the
              former, there is no string; and for the latter, there is a string
              but it's a null/empty string.  Correct?
              \_ Possibly, but if you were to malloc a string and assign
                 its lvalue to *str's rvalue then str==null means that
                 you are checking to see if you lost the rvalue for the
                 str. So theoretically the string could still exist if
                 it hadn't been probably freed and you'd have a
                 memory leak. For the latter if you created an automatic
                 character array the memory stays assigned to str regardless
                 of terminating it at the beginning. There is no way to
                 release the memory for an automatic variable unless you
                 do something really wonky. So neither really checks for
                 a lack of a string. The former checks to see if the pointer
                 is pointing to a string, the second checks to see if the
                 first char of a string is the terminator.
        \_ The latter.  "Empty string" is a better term to use than "null
           string".
           \_ I always assumed that an empty string is a string that exists
              but is empty, ie "", and that NULL string refers to the case
              where the string pointer is NULL.  /me shrugs
              \_ Typically you see this as char* p = NULL.
                 p is a char pointer.  p points to NULL.
        \_ If the term uses "string", that means it's NUL-terminated.
           Therefore it means "".  A char* that's NULL is a null pointer.
           But probably prefer "empty string" for clarity.
           \_ You mean a char* that points to NULL. a char* that is NULL,
              well, that doesn't exist. Since an array is passed like
              a char* in C, a string which is "" is essentially the
              same a char* pointing to NULL.
              \_ Err, yeah.  I think you might want to rethink that position.
              \_ What?  The previous poster's explanation and terminology
                 was correct.
              \_ char* cptr = NULL; // null pointer
                 char* cptr = ""; // empty string (== "null string" (?))
                                  // "" is \0 in memory.
                 Those aren't the same. You can deference the empty string.
2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
2014/1/14-2/5 [Computer/SW/Languages/C_Cplusplus] UID:54763 Activity:nil
1/14    Why is NULL defined to be "0" in C++ instead of "((void *) 0)" like in
        C?  I have some overloaded functtions where one takes an integer
        parameter and the other a pointer parameter.  When I call it with
        "NULL", the compiler matches it with the integer version instead of
        the pointer version which is a problem.  Other funny effect is that
        sizeof(NULL) is different from sizeof(myPtr).  Thanks.
	...
2011/3/7-4/20 [Computer/SW/Languages/C_Cplusplus] UID:54056 Activity:nil
3/7     I have a C question.  I have the following source code in two identical
        files t.c and t.cpp:
                #include <stdlib.h>
                int main(int argc, char *argv[]) {
                  const char * const * p1;
                  const char * * p2;
	...
2009/7/21-24 [Computer/SW/Languages/Java] UID:53168 Activity:moderate
7/20    For those who care btw, it looks like eclipse is now A Standard Tool
        at UCB ugrad cs, probably replaced emacs.  Furthermore, people get
        angry at seeing Makefiles, (since eclispe takes care of that).  I
        guess it's just a sign of the times.
        \_ The more people at my work use eclipse the less the code is
           managable in emacs.  I'm not sure which application's fault
	...
2007/3/9-11 [Computer/SW/Languages/C_Cplusplus] UID:45917 Activity:nil 54%like:45865
3/9     When I start trn in a shell, I always get this:
        "*** glibc detected *** malloc(): memory corruption: 0x08091600 ***
        Abort"
        But when I run trn inside the shell buffer in emacs, the problem
        doesn't happen.  Any idea?  Thanks.
	...
2007/3/4-6 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Mail, Computer/HW/Memory] UID:45865 Activity:nil 54%like:45917
3/4     trn crashes on me upon startup:
        "*** glibc detected *** malloc(): memory corruption: 0x08091618 ***
        Abort"
        Any idea?  Thanks.
	...
2006/1/25-27 [Computer/HW/Memory] UID:41522 Activity:nil
1/25    I'm working on a program in windows which is having memory problems.
        When I allocate memory with new or malloc, it seems to reserve more
        memory than I request (using VM Valiator to monitor this).  Even if I
        delete the memory there is still a "reserved" chunk that doesn't seem
        to ever get used by other code.  I'm using VC++ 6 btw.  Anyone have an
        idea of what might be going on?
	...
2005/9/9-13 [Computer/SW/OS/OsX] UID:39595 Activity:low
9/9     Does OSX gcc still not support weak symbol definitions?  ie, I
        can't redefine malloc or new? (In this case actually I'm defining
        something as weak, either with #pragma weak or
        __attribute__((weak)) but OSX doesn't seem to support either!)
        -jrleek
        \- hello, have you tried __attribute__((weak_import)). what gcc
	...
2005/6/24-27 [Computer/SW/SpamAssassin] UID:38285 Activity:nil
6/24    In my procmail log file, it says:
                csh in malloc(): warning: recursive call
                Out of memory.
        What is the meaning of this?
        \_ helps if you show us your .procmailrc
          \_ It's hundreds of lines long.  I was thinking it was
	...
2005/6/23-25 [Computer/SW/Languages/C_Cplusplus] UID:38255 Activity:low
6/22    Technical question:  My friend is trying to program a
        single-threaded signal based server.  He's using the icc compiler
        on 64-bit linux.  However, the following problem comes up.  The
        server is working and calls malloc.  Malloc grabs the allocation
        mutex (thread-safe!), then a signal comes in.  The signal
        interrupts malloc and calls the handler function.  The handler
	...
2005/2/15-16 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Compilers] UID:36174 Activity:moderate
2/15    Technical question:  we have a memory leak in our C code, we think,
        but it's not the sort of memory leak where the memory's unreferenced.
        What we'd like to do is sort of a poor-man's profile, we want
        to know who calls our memory allocator "New"...  Sorta like a stack
        trace.  Using an actual profiler is sort of difficult 'cause it's
        a parallel application.  Thanks,  --peterm
	...
2005/1/24-26 [Computer/SW/Unix] UID:35874 Activity:low
1/24    How do I find out the maximum allowable process size on lesbians?
        \_ malloc
           \_ uh, how about finding out without getting squished?
        \_ Run "limit".
[ deleting bitch ]
           \_ limit is a csh thing.
	...
2004/12/7-8 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages] UID:35200 Activity:low
12/7    Optimization time: gprof shows 310k calls to a certain constructor
        (a very simple, very important object that is often stack-allocated
        into large arrays- eg "MyObject msgs[1000];").  Rather than calling
        the constructor 1000 times, is there a way to have a special array ctor
        that's called (once) and zeroes out the array en masse?  TIA.
        \_ Geezus, why are you constructing 310k objects? Make a static array
	...
2012/7/19-11/7 [Computer/SW/Languages/C_Cplusplus] UID:54439 Activity:nil
7/19    In C or C++, how do I write the code of a function with variable
        number of parameters in order to pass the variable parameters to
        another function that also has variable number of parameters?  Thanks.
        \_ The usual way (works on gcc 3.0+, Visual Studio 2005+):
               #define foo(fmt, ...) printf(fmt, ##__VA_ARGS__)
           The cool new way (works on gcc 4.3+):
	...
2010/8/12-9/7 [Computer/SW/Languages] UID:53921 Activity:nil
8/12    Judge Walker denies Stay. Prop 8 null and void from next Wednesday:
        <DEAD>ecf.cand.uscourts.gov/cand/09cv2292<DEAD>
	...
2009/12/26-2010/1/19 [Computer/SW/Languages/Misc, Computer/SW/Graphics] UID:53604 Activity:nil
12/26   Hey you stupid web developers, stop making web sites with
        CONSTANT FONT SIZE and CONSTANT WIDTH/HEIGHT. Dumb ass
        graphics artist... please learn something about computers
        and usability!
        http://browsersize.googlelabs.com
        \_ "Stupid web-developers" is redundant. "Stupid" or
	...
2009/8/27-9/9 [Computer/SW/OS/Windows] UID:53306 Activity:nil
8/27    '"Fatal flaw" in Windows 7 raising eyebrows'
        http://tech.yahoo.com/blogs/null/146995
        \_ stupid journalism. --mac user
	...
2009/4/30-5/6 [Computer/Theory] UID:52923 Activity:nil
4/30    Sorting question!  I have n sorted arrays of doubles.  What's the
        fastest way to sort them into 1 big sorted array?
        \_ as mentioned below: you are describing one half of mergesort
        \_ You really have to ask this question?
           \_ You don't know either, huh?
        \_ If three are n sorted arrays of m doubles each, I think the fastest
	...
2009/4/5-5/3 [Computer/SW/Languages, Computer/HW/Drives] UID:52801 Activity:nil
4/5     Tuesday at 10:00PM I will be taking down Soda temporarily to migrate
        disk arrays.  This is an expected part of our move to the new server.
        The downtime should be minimal - I'll be remounting /home read-only
        for an hour or so while I run a final mirror over to the new array
        and then will reboot Soda onto the new array. The final migration
        will come at a slightly later time - this is in preparation for
	...