Search:

Type: Posts; User: christop

Page 1 of 20 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    6
    Views
    134

    Reason 2 is a good enough reason to use "sizeof...

    Reason 2 is a good enough reason to use "sizeof (char)", but the standards actually guarantee/mandate that "sizeof (char) == 1".

    But my preferred way to write that code is like this:



    char...
  2. Thread: sizeof()

    by christop
    Replies
    7
    Views
    173

    sizeof gives you a compile-time constant value...

    sizeof gives you a compile-time constant value because the compiler knows how big all objects or types are at compile time. So if your code says "sizeof (int)", the compiler will effectively replace...
  3. Replies
    4
    Views
    129

    The constraints seem wrong because they exclude...

    The constraints seem wrong because they exclude the last index. Using the given example, it's not possible to pick "BBB" because that's at index 8 (M = 8), but M must be less than 8. The constraints...
  4. Replies
    9
    Views
    206

    Yes, that's a fair point. I think it's a pity...

    Yes, that's a fair point.

    I think it's a pity that there's no standard file positioning functions in C that takes/returns a 64-bit or longer integer type.
  5. Replies
    9
    Views
    206

    fgetpos and fsetpos take a pointer to fpos_t...

    fgetpos and fsetpos take a pointer to fpos_t (which should be a type that's large enough for a "large" file). These have been around since C89, so they're hardly platform-specific.

    There's also...
  6. Replies
    6
    Views
    176

    Merriam-Webster...

    Merriam-Webster says:


    So "DLL" is an acronym. (And an acronym is an abbreviation.)
  7. By the way, the main function returns int, not...

    By the way, the main function returns int, not void.
  8. Replies
    15
    Views
    660

    Haha, the S........horpe problem strikes again!...

    Haha, the S........horpe problem strikes again! (LOL, it's censored even when I Preview Post! That should be "S c u n t h o r p e".)
  9. Replies
    4
    Views
    204

    class CompilationError { void...

    class CompilationError {
    void nonConstMethod();
    void constMethod() const { nonConstMethod(); } // can't do this
    };


    In this case, the "const" after "constMethod()" tells the compiler...
  10. Replies
    4
    Views
    204

    What is the context? Is this sentence preceded by...

    What is the context? Is this sentence preceded by "The following are errors"?
  11. It appears that gcc is being somewhat "helpful"...

    It appears that gcc is being somewhat "helpful" by defining _POSIX_C_SOURCE when you include one of the standard headers if _GNU_SOURCE is defined (see /usr/include/sys/features.h). _GNU_SOURCE is...
  12. sqrtf is in C99. You don't need POSIX for that...

    sqrtf is in C99. You don't need POSIX for that function.

    Besides, _POSIX_C_SOURCE is a user-defined macro; it's up to you to define that macro to tell the implementation to conform to a particular...
  13. Thread: Mutex

    by christop
    Replies
    7
    Views
    236

    It sounds like you need a readers-writer lock....

    It sounds like you need a readers-writer lock. See functions that use the pthread_rwlock_t type.
  14. Replies
    6
    Views
    269

    Or try this: struct dev_state *ds ...

    Or try this:


    struct dev_state *ds = (struct dev_state *)&jcpheader[1];
  15. Replies
    6
    Views
    328

    Note that fgets() keeps the linefeed ('\n')...

    Note that fgets() keeps the linefeed ('\n') character at the end of the string. You can easily remove that with this line of code after fgets():


    password[strcspn(password, "\n")] = '\0';
    ...
  16. Replies
    29
    Views
    1,671

    You can use OOP techniques in C, though it has to...

    You can use OOP techniques in C, though it has to be done "manually". As one example, the stdio interface is OO--each method operates on a "FILE" object (either implicitly like "printf" or explicitly...
  17. Well, as I mentioned, *str1 is a char, so you can...

    Well, as I mentioned, *str1 is a char, so you can compare it against another char like '\0'. For example:


    if (*str1 == '\n') {
    // ...
    }

    The * in front of str1 dereferences the pointer,...
  18. It looks like you misunderstand how to use...

    It looks like you misunderstand how to use pointers. str1 is a pointer to char. *str1 is a char. You can't meaningfully compare a pointer to char (like str1) with a char (like '\0' or '\n').

    Also,...
  19. Yeah, it might be a problem with a pre-ANSI...

    Yeah, it might be a problem with a pre-ANSI compiler, but fortunately it should work fine with almost any standard C compiler made in the last 30 years.

    (It's definitely something to be aware of...
  20. I generally give the struct and the typedef type...

    I generally give the struct and the typedef type the same name:

    typedef struct some_name {
    // variables here
    struct _some_name *ptr;
    } some_name;

    There's no name conflict because...
  21. Are you sure Arduino's "new" operator doesn't...

    Are you sure Arduino's "new" operator doesn't call the class's constructor? It's my understanding that "operator new" is responsible only for allocating memory, and the compiler will generate the...
  22. Replies
    19
    Views
    569

    You declare name (in struct PERSON) to be an...

    You declare name (in struct PERSON) to be an array of 20 pointers to char. From your usage of name, that doesn't seem to be the correct type.
  23. Replies
    19
    Views
    569

    I'm guessing you had char name[10]; and then...

    I'm guessing you had char name[10]; and then tried to do name = "thomas";, which isn't allowed because name is an array, and you can't assign to an array.
  24. Replies
    9
    Views
    526

    Why don't you try it? You could have had an...

    Why don't you try it? You could have had an answer from your compiler already.
  25. Replies
    6
    Views
    287

    Don't use void main()...

    Don't use void main().




    You can, but it expands 2 lines into 8, which doesn't make the code any more readable or clear as to its purpose.
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4