Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ClausW

macrumors newbie
Original poster
Mar 24, 2012
1
0
Dear forummers,
I have recently installed Lion on my macbook and then I installed the new Xcode, but upon discovering that the terminal gcc was no longer working I also installed that through Xcode(sth like command line tools).

Anyway, gcc is installed, but it works very strangely. The function rand() began no longer working properly(always giving me approx. same numbers), and even a simple for loop stopped working, getting stuck in the last term of it and not being able to escape from it.

I might post code here, but it won't be of use: My program was working perfectly till I got the new gcc. I can't believe I am the only one having difficulties with the new gcc.

Upon entering "gcc -v" it returns: gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Dear forummers,
I have recently installed Lion on my macbook and then I installed the new Xcode, but upon discovering that the terminal gcc was no longer working I also installed that through Xcode(sth like command line tools).

Anyway, gcc is installed, but it works very strangely. The function rand() began no longer working properly(always giving me approx. same numbers), and even a simple for loop stopped working, getting stuck in the last term of it and not being able to escape from it.

I might post code here, but it won't be of use: My program was working perfectly till I got the new gcc. I can't believe I am the only one having difficulties with the new gcc.

Upon entering "gcc -v" it returns: gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)

Two possibilities: 1. Your program contained some serious bugs, but worked by pure chance with the older compiler version. 2. Your program was correct, but the newer compiler version is broken. So what is more likely? Without code, we won't know. If an experienced developer thinks they ran into a compiler bug, there is a 99% chance they are wrong. For inexperienced developers the number is higher.

I'd try a different compiler, like LLVM, and see what happens. If you have XCode 4.3.1, you could try LLVM and the new standard library implementation.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,415
A sea of green
The function rand() began no longer working properly(always giving me approx. same numbers), ...

rand() must be seeded. If you don't seed it, or seed it with the same or similar values, it will produce the same or similar outputs.

This is one reason the man page's brief description for rand is this:
rand, srand, sranddev, rand_r -- bad random number generator
(Emphasis added)

Frankly, without knowing how you're seeding it, and without knowing how you're using it, there's no way to diagnose the problem. The same thing goes for your "simple for loop". We don't know what you coded, and anyon'e idea of a simple for loop can mean anything in the actual code.

In short, without code, it's all just guessing.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.