Getting sporadic segmentation fault (core dump)

Hi,

When I debug in visual studio and step through every line of a function, there is no seg fault. But if I just step over it, there is a seg fault...

If I compile it on my school server, there is a sporadic seg fault, meaning there is no pattern as to when it happens. I think it might have something to do with the srand and rand???

1
2
3
4
5
6
7
8
9
10
11
12
#include <cstdlib>
#include <ctime>

int sixSidedDice = 0;
	
	for (int i = 0; i < 2; i++) {
		unsigned seed = time(0);
		srand(seed);
		sixSidedDice += (rand() % 6) + 1;
	}

	doSomething(sixSidedDice);
As of now, that code shouldn't compile. Could you post your whole program please?
Also you should only call srand() once, usually early in main().

see next post...
Last edited on
There seems to be an error with __time64_t __cdecl _time64
It seems timeptr couldn't be evaluated, thus resulting in unable to read memory

It stopped at this line in time64.c
tim = (__time64_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64);

Anyone know what this mean?

Edit: I think I fixed it. It seems jlb was correct, I didn't need to call srand() multiple times. I was doing it at least two times each derived class.
Last edited on
Topic archived. No new replies allowed.