質問

Can anyone please let me know how to deterimine the number of address lines in a processor using C ? This can't be equal to size of the processor registers since the number of address lines may be different compared to the size of registers (for example in the 8086 the address lines are 20 while size of registers is 16).

Similarly, can we find the word size of RAM (meaning the size of each addressable location) through a C program?

役に立ちましたか?

解決

The short answer to pretty much all of these is that (at least in a portable way that's really defined by C itself) you can't.

Address lines, for example, is a particularly tough one. Just for example, quite a DSPs have two or even three completely separate address spaces connected to an equal number of physical memory channels -- and each will potentially have a unique size. Along with that, even if there are N address lines on the processor, there may (and often will) be less memory than that actually connected.

That said, sizeof(void *) * CHAR_BIT will usually give at least a reasonable approximation of the number of address lines -- at least the number theoretically allowed by the architecture, though the amount of addressable memory may well differ.

The standard says int is supposed to be the "natural size suggested by the processor". More often than not (but definitely not always) that's the same as the size of the processors integer registers.

他のヒント

As far as I know the answer to both questions is implementation defined. There's no standardized concepts of these things in the C language, hence there's no standard code to write the tests. You may be able to guess them, but that doesn't make your code portable. A specific compiler suite may provide these facilities, but again that won't make your code portable.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top