views:

143

answers:

3

Hey,

I'm trying to compile someone's code right now and the person is using a variable HZ (which I think stands for Hertz for the hertz of the cpu) but the compiler is complaining that the variable is not defined. My guess is that the person didn't include the correct header file.

So does anyone know which header file, HZ is defined in?

Thanks

Edit: Compilation works on Debian g++ version 4.3.2
The setup I'm using - OSX Leopard 10.5.8, g++ version 4.0.1 is where it fails.

A: 

it might be expected to come from the command line:

c++ -DHZ=1000 file.cpp -o file.o

hard to say more w/o more details. what operating system is this?

just somebody
This is OSX Leopard 10.5.8, g++ version 4.0.1. I tried it on Debian with g++ version 4.3.2 and it worked. Maybe my g++ is too old?
Sid
+4  A: 

On my Linux box, it's defined in /usr/include/asm/param.h:#define HZ 100

I can't find a definition anywhere on my Mac OS X box.

Paul Tomblin
+4  A: 

Paul's answer is correct, but I'll expand a little.

Linux has a compile-time option which determines the frequency of the kernel's timer. At approximately the frequency that HZ is defined to, the kernel scheduler will interrupt processes and begin its scheduling work. (A related feature is the DynTicks option, which elides the HZ value, and changes the interrupt frequency based on the workload.) The most common setting is 100. Highly responsive systems might use 1000. Recent kernel versions use a default of 250. Systems with heavy computational workloads might use a smaller value (to minimize the effect of the scheduler).

Thus it is a very Linux-specific value, and you'll only find it defined in /usr/include/asm/param.h

Since 100 is a common value, you might be safe in simply adding -DHZ=100 to your CXXFLAGS variable. This will by no means mean that the program will actually work on OS X, only that it might compile.

greyfade