Comment by 1718627440

3 months ago

> static char buf[64];

In a function? That makes the function not-threadsafe and the function itself stateful. There are places, where you want this, but I would refrain from doing that in the general case.

Holy moly.. Thread safety.. Good point and Bad point. I myself use threads sparsly, so I dont intermix calls between threads..

  • It also has different behaviour in a single thread. This can be what you want though, but I would prefer it to pass that context as a parameter instead of having it in a hidden static variable.

    • What different behaviour you mean? static in function means that this is just preallocated somewhere in data, not on stack nor heap. Thats it. Yes, its not thread safe so should never be used in libraries for any buffering.

      But in program, its not bad. If I ever need multiple calls to it in same thread:

        static char buf[8][32];
        static int z;
        char *p=buf[z];
        z=(z+1)&7;
      

      Works pretty well ;)

      4 replies →