|
John R. Shaw wrote: Try that same logic in C or C++ and you will see it does not apply.
I know - this caught me out a few times when I first moved over to .NET. I must admit that it really bugged me - especially when attempting to convert values.
.NET standardised on int being Int32 and long being Int64.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
What really bugs me some times is that even though the C and C++ languages are standardized the size of the types are not. That is even the size of ‘char’ is not guaranteed to be a byte, at least that is what Bjarne Stroustrup says and he should know.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Thank god for sizeof I say.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
You do know that ‘sizeof’ returns a number based on the ‘char’ size don’t you. Therefore if the character size was 16 bits then ‘sizeof(char)’ would still be 1 and not the number of bytes.
Isn’t non-specific specifications wonderful.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
char is 1 byte, by definition. However, this byte may not be one octet (8 bits), so that the system uses e.g. 9-bit (rare) or 16-bit (used on some DSPs) "bytes".
--
Marcus Kwok
|
|
|
|
|
Sorry to point this out, but that's by convention but not by the standard. All the standard states is that sizeof(short) <= sizeof(int) <= sizeof(long). Most implementations, however, have adopted the convention that an int is register size. However, a 32-bit compiler could choose short as 16-bit, int as 32-bit and long as 64-bit without breaking the standard, it just may not interoperate with code from other compilers very well.
Similarly char is a character - this could be 8-bit or 16-bit. In C++, they tend (I've never seen an exception) to be 8-bit, but the standard doesn't actually rule it out.
|
|
|
|
|
Rob Grainger wrote: Similarly char is a character - this could be 8-bit or 16-bit. In C++, they tend (I've never seen an exception) to be 8-bit, but the standard doesn't actually rule it out.
Some DSPs use 16-bit chars. Also, some weird machines (maybe it was the PDP-11?) use 9-bit chars. The standard just says that char is at least 8 bits.
--
Marcus Kwok
|
|
|
|
|
Thanks! I can never remember which systems use character sizes other than 8-bits, I just remember there are a few out there. Of course I know nothing more than that or even what language compilers support those systems.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I did not look it up, but at one time the C standard stated that an int was the size of a machine word and a short was 16-bits. I could be wrong, since it has be some years since I read it.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
John R. Shaw wrote: Do you know what a long pointer is? I do.
long pointers are used to access memory that is located in the other segment(intersegment).
Am I right?
Regards,
Arun Kumar.A
|
|
|
|
|
Actually no! Long pointers are not used any more and where used to overcome the limitations of PC memory access. The PC was limited to accessing only 64k, minus a few bytes for the systems use, so that was the max you could allocate with standard C (malloc). A normal pointer was only 16 bits, and a long pointer was a 32 bit pointer which required the compiler to generate code that allowed you to access more that 64k. Microsoft had the keyword ‘_far’ which told the compiler to make the pointer 32 bits instead of 16 bits and generate the required code. When Windows 95 came along and VC6 came out the ‘_far’ keyword was no longer supported, because it was not longer needed. All the ‘lp’ references in the code no longer mattered because all the pointers where now the same size, but if your previous code used the macro definitions like ‘LPSTR’ then it would still compile without error because the macros had been changed. If you had used the keyword ‘_far’ in any of your code, then you had to go in and remove it so you could compile the same code on the new compiler.
That is pretty much it, ‘lp’ means ‘p’ now days.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Thank you very much for your reply.
But, in C Language, how to access the memory 0xb8000000
which is the memory address for VDU.
Similarly , how to execute the POST function
located at 0xffff000 without far pointer?
Regards,
Arun Kumar.A
|
|
|
|
|
Now days: unsigned char* p = (unsigned char*)0xB8000000L;
Old days: unsigned char _far* p = (unsigned char _far*)0xB8000000L;
Used to do stuff like that all the time to directly access video memory and other hardware, but modern operating systems do not allow that any more. Accept for older code, which it places in a sandbox (its own processing space) so it can keep an eye on it, and even then it may not allow it. Direct access now requires a driver down at ring 0 to access hardware directly, but there is usually something like DirectX that does it for you.
Note that both the addresses you mentioned are 32 bit and are therefore just ordinary pointers on a 32 bit machine.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
|
A fragment found indicating a similar naming blunder encountered in our code...
szCallerName.GetBuffer(0)
|
|
|
|
|
The rule is best when used in spirit in more degree and emphasis than in letter. There used to be one lesson in my tenth standard English book "All about the dog". I forgot the author. It used to emphasize this letter vs spirit.
|
|
|
|
|
__gc struct G
{
int i;
};
__value struct V
{
int i;
};
int main()
{
// defaults to V __gc * __nogc * ppV;
V ** ppV;
// defaults to V __gc * __nogc * __nogc * pppV;
V *** pppV;
// defaults to G __gc * __gc * ppG;
G ** ppG;
// defaults to G __gc * __gc * __nogc * pppG;
G *** pppG;
// defaults to G __gc * __gc * __nogc * __nogc * ppppG;
G **** ppppG;
}
Thanks,
Syed
|
|
|
|
|
"Do not post programming questions in this forum. This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed."
Marked as spam.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Wow - I wish I could say this was a new record. Somebody posting exactly question to the same forum, and ignoring the fact that the original was removed because this wasn't the right place to ask the question.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I think the OP is the epitome for my sig.
Cheers,
Vıkram.
Déjà moo - The feeling that you've seen this bull before.
Join the CP group at NationStates. Password: byalmightybob
|
|
|
|
|
|
i suspect a language issue.
|
|
|
|
|
Yeah... in syedhasan's native language, MC++ translates to "Horrors".
...oh, wait, that'd be English...
----
i hope you are feeling sleepy for people not calling you by the same.
--BarnaKol on abusive words
|
|
|
|
|
Shog9 wrote: MC++ translates to "Horrors".
hmmm. i thought MC++ was the new fat-n-proud rapper from Redmond...
|
|
|
|
|
Heh.
----
i hope you are feeling sleepy for people not calling you by the same.
--BarnaKol on abusive words
|
|
|
|