Thread: Thread counting problem

  1. #16
    Registered User
    Join Date
    Sep 2022
    Posts
    55
    Sorry for not being clear enough. The malloc() and free() example has been my way to tell you that you just need to document what users of your lib have to take care. You can't take care of everything where a user of your lib may fail. But you can contract what your lib does and what the user is responsible to do.

  2. #17
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by aGerman View Post
    Sorry for not being clear enough. The malloc() and free() example has been my way to tell you that you just need to document what users of your lib have to take care. You can't take care of everything where a user of your lib may fail. But you can contract what your lib does and what the user is responsible to do.
    I'm not trying to take care of everything, I'm simply trying to prevent predictable scenarios that ARE possible to catch, just because something is difficult to do does not mean it isn't worth doing, innovation hinges on that fact, additionally I don't think I'm re-inventing the wheel here, I'm sure someone else ran into this problem before too, perhaps the devs of pthreads ran into that very problem themselves and have their own solution under the hood

  3. #18
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Quote Originally Posted by awsdert View Post
    I originally looked into the atomic thing at the start but that requires C11, I'm trying to make my library compilable under
    Code:
    -std=c89 -ansi -pedantic
    Why bother supporting such an old version of the C standard? Since no existing code will be using your library (in other words, only new code will use your library), I fail to see the point in supporting C89. Even something less old like C99 would be better, and that's 24 years old at this point. And C11 is already 12 years old.

    Do you really expect users of your library to be stuck with '80s/'90s compilers? Are you planning to support obsolete platforms like PalmOS?

  4. #19
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by christop View Post
    Why bother supporting such an old version of the C standard? Since no existing code will be using your library (in other words, only new code will use your library), I fail to see the point in supporting C89. Even something less old like C99 would be better, and that's 24 years old at this point. And C11 is already 12 years old.

    Do you really expect users of your library to be stuck with '80s/'90s compilers? Are you planning to support obsolete platforms like PalmOS?
    Because like the devs of lua I like my code to be compilable under any standards complaint compiler, one of the benefits is that my code is happy with both c & c++ compilers whereas code that requires later standards sometimes has the issue of not compiling with a c++ compiler, that and it's more interesting to support old standards then it is to force newer standards, also tends to force you to really understand what you're doing with your code.

  5. #20
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Quote Originally Posted by awsdert View Post
    Because like the devs of lua I like my code to be compilable under any standards complaint compiler
    Sure, but keep in mind that Lua started development in 1993, when the only C standard that existed was C89, so any later standard wasn't even an option.

    Quote Originally Posted by awsdert View Post
    whereas code that requires later standards sometimes has the issue of not compiling with a c++ compiler
    But why would you need to compile C code (especially something like a library) with a C++ compiler? If you want the library to support both C and C++, compile it with the correct compiler (i.e., a C compiler) and make the header files usable in both C and C++ (hint: use extern "C" when a header is used in C++, i.e., when the __cplusplus preprocessor macro is defined). You can even define macros in a common header to simplify this:

    Code:
    #ifdef __cplusplus
    #  define CPP_START extern "C" {
    #  define CPP_END }
    #else
    #  define CPP_START
    #  define CPP_END
    #endif
    And then put CPP_START at the top and CPP_END at the bottom of each header file. I do things like this often and it works fairly painlessly.

  6. #21
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by christop View Post
    Sure, but keep in mind that Lua started development in 1993, when the only C standard that existed was C89, so any later standard wasn't even an option.



    But why would you need to compile C code (especially something like a library) with a C++ compiler? If you want the library to support both C and C++, compile it with the correct compiler (i.e., a C compiler) and make the header files usable in both C and C++ (hint: use extern "C" when a header is used in C++, i.e., when the __cplusplus preprocessor macro is defined). You can even define macros in a common header to simplify this:

    Code:
    #ifdef __cplusplus
    #  define CPP_START extern "C" {
    #  define CPP_END }
    #else
    #  define CPP_START
    #  define CPP_END
    #endif
    And then put CPP_START at the top and CPP_END at the bottom of each header file. I do things like this often and it works fairly painlessly.
    The reason I want it to compile under c++ also is because I cannot garuntee that some dev or group or company somewhere will feel like compiling it as c++ instead and just using it in their c++ code directly, unlikely I agree but one never knows, and also I know about the extern "C", that was one of the 1st things I wrapped in my headers using PAW_OPEN_C_API/PAW_SHUT_C_API & PAW_OPEN_CPP_API/PAW_SHUT_CPP_API

  7. #22
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Quote Originally Posted by awsdert View Post
    The reason I want it to compile under c++ also is because I cannot garuntee that some dev or group or company somewhere will feel like compiling it as c++ instead and just using it in their c++ code directly
    You can easily guarantee that people won't compile it as C++ if it doesn't compile as C++.

  8. #23
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by christop View Post
    You can easily guarantee that people won't compile it as C++ if it doesn't compile as C++.
    If I don't need the constraint then why should I put it in there when the only thing it does is make development easier, if the same problem can be solved without the constraint then it is poor programming to do it with the constraint

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with counting problem
    By ownerpurez in forum C++ Programming
    Replies: 5
    Last Post: 02-12-2013, 04:30 AM
  2. Help with word counting problem
    By optimizer_777 in forum C Programming
    Replies: 6
    Last Post: 01-20-2012, 04:46 PM
  3. Problem with counting
    By jinjinodie in forum C++ Programming
    Replies: 5
    Last Post: 10-23-2010, 10:05 AM
  4. Similar thread: More token counting
    By Imanuel in forum C Programming
    Replies: 3
    Last Post: 07-21-2010, 04:54 AM
  5. counting problem
    By javani in forum C Programming
    Replies: 16
    Last Post: 04-03-2007, 11:25 PM

Tags for this Thread