Hi,
I came across this question from a website..
According to the C++ standard, what is an object's internal representation
in memory guaranteed to be?
a) Initialized
b) On a word boundary
c) Contiguous
d) On stack
e) on heap
I am not sure which is the correct option out of 1,2 & 3?
(It is not some homework assignment)..
Thanks in advance
Arun 9 8961
Arun Goel wrote: I came across this question from a website..
According to the C++ standard, what is an object's internal representation in memory guaranteed to be? a) Initialized b) On a word boundary c) Contiguous d) On stack e) on heap
I am not sure which is the correct option out of 1,2 & 3?
If by "1,2 & 3" you mean 'a', 'b' and 'c', respectively, then 'c'
_seems_ to me the only valid answer. I challenge you to find the
corresponding wording in the Standard document, or at least the
clause/subclause/paragraph or the page number.
(It is not some homework assignment)..
Why not? It might as well be. Of course, if I were giving such
assignment and then checking the answer, a simple "it's 'c'" would
not fly. You'd still have to quote the Standard for me.
V
* Victor Bazarov: Arun Goel wrote: I came across this question from a website..
According to the C++ standard, what is an object's internal representation in memory guaranteed to be? a) Initialized b) On a word boundary c) Contiguous d) On stack e) on heap
I am not sure which is the correct option out of 1,2 & 3? If by "1,2 & 3" you mean 'a', 'b' and 'c', respectively, then 'c' _seems_ to me the only valid answer.
I agree with that, but I had a _very_ long & heated discussion with David
Abrahams (of Boost and the C++ committee) over in clc++m; he disagreed, and
stated -- with no one contradicting that -- that his opinion was the
intention of the committee on what the wording should express.
The immediate interpretation problem is whether a "region" is necessarily
contigous or not.
I say yes, contigous, Dave said no, not necessarily.
The semantics problem is then whether the standard's text elsewhere is or
can be meaningful with either interpretation. I say only with "yes". Dave
said that's not so (but I'm still not sure whether he meant only with "no").
Given that disagreement the only correct answer, wrt. to "guaranteed", is:
none of the above.
I challenge you to find the corresponding wording in the Standard document, or at least the clause/subclause/paragraph or the page number.
(It is not some homework assignment).. Why not? It might as well be.
It's a bit advanced for a homework assignment, where you have to know all
about things such as multiple virtual inheritance.
Of course, if I were giving such assignment and then checking the answer, a simple "it's 'c'" would not fly. You'd still have to quote the Standard for me.
Perhaps it could marked on the basis of whether the student's circling of an
alternative falls into the hole on the teacher's Correct Parroting Card.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
* EventHelix.com: The memory representation of a class is undefined in C++. Memory representation for structures (with public members only) is contiguous.
A C++ 'struct' is a C++ class. A C++ 'class' is a C++ class. The only
difference between 'struct' and 'class' is the default access.
The memory representation of a class instance is not undefined in C++.
The memory representation of a class instance is not currently guaranteed to
be contigous -- although for what I regard as the most natural
interpretation it is so in practice.
The memory representation of a variable, on the other hand, seems to me to
be guaranteed to be contigous, but at least one expert disagrees with that.
Finally, public members only is not a useful criterion for anything in this
regard.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jack Klein wrote: EventHelix wrote:
The memory representation of a class is undefined in C++. Memory representation for structures (with public members only) is contiguous. ...and memory representation for all other C++ objects, like scalars, pointers, floating point types, and arrays of anything, is contiguous. As is dynamically allocated memory.
cat main.cc
#include <iostream>
#include <string>
int main(int argc, char* argv[]) {
std::string s("Jack Klein");
std::cout << "sizeof(std::string) = "
<< sizeof(std::string) << std::endl;
std::cout << "sizeof(s) = "
<< sizeof(s) << std::endl;
return 0;
}
g++ -Wall -ansi -pedantic -o main main.cc ./main
sizeof(std::string) = 4
sizeof(s) = 4
Is std::string s an object?
If the string "Jack Klein" is a contiguous part of that object,
why doesn't it show up in the sizeof s?
E. Robert Tisdale wrote: Jack Klein wrote:
EventHelix wrote:
The memory representation of a class is undefined in C++. Memory representation for structures (with public members only) is contiguous.
...and memory representation for all other C++ objects, like scalars, pointers, floating point types, and arrays of anything, is contiguous. As is dynamically allocated memory.
> cat main.cc #include <iostream> #include <string>
int main(int argc, char* argv[]) {
std::string s("Jack Klein"); std::cout << "sizeof(std::string) = " << sizeof(std::string) << std::endl; std::cout << "sizeof(s) = " << sizeof(s) << std::endl;
return 0; }
> g++ -Wall -ansi -pedantic -o main main.cc > ./main sizeof(std::string) = 4 sizeof(s) = 4
Is std::string s an object?
Of course it is.
If the string "Jack Klein" is a contiguous part of that object, why doesn't it show up in the sizeof s?
Who said it was [part of the object]?
Victor Bazarov wrote: E. Robert Tisdale wrote:
Jack Klein wrote:
EventHelix wrote:
The memory representation of a class is undefined in C++. Memory representation for structures (with public members only) is contiguous. ...and memory representation for all other C++ objects, like scalars, pointers, floating point types, and arrays of anything, is contiguous. As is dynamically allocated memory. > cat main.cc #include <iostream> #include <string>
int main(int argc, char* argv[]) {
std::string s("Jack Klein"); std::cout << "sizeof(std::string) = " << sizeof(std::string) << std::endl; std::cout << "sizeof(s) = " << sizeof(s) << std::endl;
return 0; }
> g++ -Wall -ansi -pedantic -o main main.cc > ./main sizeof(std::string) = 4 sizeof(s) = 4
Is std::string s an object?
Of course it is.
If the string "Jack Klein" is a contiguous part of that object, why doesn't it show up in the sizeof s?
Who said it was [part of the object]?
Are you saying that "Jack Klein" is *not* part of std::string object s?
E. Robert Tisdale wrote: Victor Bazarov wrote:
E. Robert Tisdale wrote:
Jack Klein wrote:
EventHelix wrote:
> The memory representation of a class is undefined in C++. > Memory representation for structures (with public members only) is > contiguous.
...and memory representation for all other C++ objects, like scalars, pointers, floating point types, and arrays of anything, is contiguous. As is dynamically allocated memory.
> cat main.cc #include <iostream> #include <string>
int main(int argc, char* argv[]) {
std::string s("Jack Klein"); std::cout << "sizeof(std::string) = " << sizeof(std::string) << std::endl; std::cout << "sizeof(s) = " << sizeof(s) << std::endl;
return 0; }
> g++ -Wall -ansi -pedantic -o main main.cc > ./main sizeof(std::string) = 4 sizeof(s) = 4
Is std::string s an object? Of course it is.
If the string "Jack Klein" is a contiguous part of that object, why doesn't it show up in the sizeof s? Who said it was [part of the object]?
Are you saying that "Jack Klein" is *not* part of std::string object s?
Yes, that's what I am saying. Just like a file on disk is not part of
an open stream object.
V This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alexander Sourjikov |
last post by:
Hi pals,
i am using python for numerical simulations and noticed that
when i assign a Float variable say 0.1 python sees it like
0.10000000149011612.
I have also checked if python really takes...
|
by: ej |
last post by:
I ran into something today I don't quite understand and I don't know all the
nitty gritty details about how Python stores and handles data internally.
(I think) I understand why, when you type in...
|
by: Sathyaish |
last post by:
When you say char in C, it internally means "an unsigned small integer
with 1-byte memory", right? More importantly, the internal
representation of char does not mean "int" as in...
|
by: archana |
last post by:
Hi all,
I have one question regarding hashing in .net
I have two string containing same data. When i see hashcode by calling
gethascode, i am getting same value.
I want to know how...
|
by: khan |
last post by:
Hi,
I read that pointer representation can non-zero bit pattern, machine
specific.Compiler when comes accross value '0' in pointer context,
converts it to machine specific null pointer...
|
by: DougAtHost |
last post by:
In perl, how can I get the actual internal floating point data for a variable? In C, I can do something like this
{
float f = 5.88;
unsigned char a;
memcpy(a, (void *)&f,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |