• Re: Rethink your use of memset (or specify size_t)

    From DFS@21:1/5 to Relf on Fri Feb 16 11:15:04 2024
    On 2/16/2024 10:21 AM, Relf wrote:
    You (DFS) replied ( to me ):
    Try it with [int64_t], DFS:

    int64_t rows = 1000000000, bytes = (rows+1) * sizeof(int);
    int *randarrRelf = (int *)malloc( bytes );
    memset( randarrRelf, 0, bytes );

    I did try it. [ memset() failed, "long" (occasionally) fails too ]

    As a wise man once said, "Linux is for losers".

    I compiled and ran my code on Windows, using tcc.

    My 'fill array with loop' ALWAYS works, on Linux and Windows.

    Your usage of memset was incorrect, because you specified bytes as an
    int, but memset expects size_t.

    void *memset(void *str, int c, size_t n)

    So use:
    size_t bytes = (rows+1) * sizeof(int);
    or
    int64_t bytes = (rows+1) * sizeof(int);


    Rethink your use of memset (or specify size_t).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)