Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 242,547 of 243,242    |
|    David Brown to Michael Sanders    |
|    Re: srand(0)    |
|    23 Dec 25 19:15:24    |
      From: david.brown@hesbynett.no              On 23/12/2025 15:45, Michael Sanders wrote:       > On Tue, 23 Dec 2025 08:25:59 +0100, David Brown wrote:       >       >> It is not the compilers that are different, it is the C standard       >> libraries that are different. gcc is a compiler, not a library, but you       >> are probably using glibc with it by default. musl is a library, not a       >> compiler. There is no reason to suppose that different C standard       >> libraries use the same implementation of rand()and srand(), so no reason       >> to suppose they would give the same sequences - though each on their own       >> will give a deterministic pseudo-random sequence based on their seeds.       >>       >> If you swap gcc with clang you will get the same results - it will       >> depend on whether you are linking with glibc, musl, or another C library.       >       > Sure enough & thank you David - I appreciate your explanation.       >       > I see where my thinking was off now. You're 100% correct       > (I'm still learning as you noticed).       >              There are people who have been in this group for decades that still have       trouble understanding the distinction between a C compiler, a C standard       library, and a C implementation (which combines both). There are C       compilers that have a standard library tightly attached or "built in" in       the same product, and others which can work with a number of different C       standard libraries. There are C standard libraries that only work with       a single compiler, and others that are much more general - though you       can't write a complete C standard library purely in fully portable C.       And C compilers can implement standard library functions in the compiler       itself (this is typically done for small functions like memcpy, or maths       functions - things that can be significantly more efficient when handled       inline by the compiler). There are many nuances involved - but you've       found a clear way to show a difference between two common C libraries,       so that's a good start.              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca