Dear friends, I have one more questions for everyone in the newsgroup:
I am preparing for an interview on UNIX/C++. Could you please identify some
of the most important questions which might be asked, so that I could best
prepare for it?
Thank you,
C++J
Jul 22 '05
71 5952
"pembed2003 " <pe********@yah oo.com> wrote in message possible function definition. The lookup (not sure how the actual virtual table is implemented but if it's something like a binary tree or hash table then...) thus takes appr. the same amount of time.
I think the virtual table is implemented as an array of pointers to
function. It works well whenever a pointer to a function of any signature
has the same size, which is normally the case. If you have a class as
follows.
Note what follows is a typical implementation, not what the standard
mandates.
class Foo {
virtual ~Foo();
virtual int f(int, int);
virtual double g(int) const;
};
then the virtual table is an array of length 3. Each element in the array
is a function pointer, but each function pointer is a different signature!
Sure, the compiler can do that, but we can't!
Thus, there are 3 C style functions.
void __Foo_destructo r(Foo *);
int __Foo_f(Foo *, int, int);
double __Foo_g(const Foo *, int);
and the virtual table is
typedef void (* __FunctionPtr)( ); // pointer to non-member function
typedef __FunctionPtr[3] __Foo_vtable_ty pe; // typedef for array of 3
function pointers
__Foo_vtable_ty pe __Foo_vtable = {
(__FunctionPtr) (&Foo_destructo r),
(__FunctionPtr) (&Foo_f),
(__FunctionPtr) (&Foo_g)
};
When you say foo->g(3) the compiler knows you mean the element
__Foo_vtable[2] and that it's real signature is double (*)(const Foo *,
int). Thus the call translates to
{
typedef double (* _Foo_vtable2)(c onst Foo *, int);
const __Foo_vtable_ty pe& __vtable = foo->__vpointer;
_Foo_vtable2 __tmp = (_Foo_vtable2)( __vtable[2]);
(*__tmp)(foo, 3);
}
In message <db************ **************@ posting.google. com>, pembed2003
<pe********@yah oo.com> writes Hi, As a new C++ programmer, I found your question very interesting. I think it takes about the same time to find and invoke base78::someth ing() and base999999::som ething(), right? Because each object carries a virtual table pointer (if the class has at least one virtual function) with an bunch of virutal function pointers to the possible function definition. The lookup (not sure how the actual virtual table is implemented but if it's something like a binary tree or hash table then...)
Unless you have virtual inheritance, there's no need for anything so
complicated - it's probably just a linear array, since the offset of
each function's entry in it is known at compile time.
thus takes appr. the same amount of time.
If I answered it incorrectly, can you provide the answer? I want to learn.
--
Richard Herring
Ioannis Vranos wrote: cj wrote: Dear friends, I have one more questions for everyone in the newsgroup:
I am preparing for an interview on UNIX/C++. Could you please identify some of the most important questions which might be asked, so that I could best prepare for it?
Thank you, C++J Here is one I would ask:
Is the following code guaranteed to be safe and portable?
You should expect a "no", even from someone who doesn't actually know
the answer ;-)
pembed2003 posted: JKop <NU**@NULL.NULL > wrote in message news:<UE******* **********@news .indigo.ie>... JKop posted:
> Peter Koch Larsen posted: > >> I do believe that that question is a very bad one. The code above >> is obviously portable, but these casts do confuse. What on earth >> are you going to do with v? Any programmers instinct is that code >> must have "a use", and it is quite difficult to see what you could >> portable do with v. > > What ever happened to just having fun? > > int main(void) > { > int monkeys[7] = { 3, 4 ,3, 2 ,2 ,34, 23 ,3 }; > > char jack reinterpret_cas t<char>(monkey s[5]);
TYPO
char jack = reinterpret_cas <char>(monkey s[5]);
> > cout << jack; } >
Hi, I am trying to compile your code using g++ in FreeBSD. g++ -v gives:
gcc version 2.95.3 20010125 (prerelease)
the whole program looks like:
#include<iostre am> using namespace std; void main(void){ int monkeys[8] = {3,4,3,2,2,34,2 3,3}; char jack = reinterpret_cas t<char>(monkey s[5]); cout<<jack<<end l; }
but it won't compile:
g++ tmp.cpp -o tmp tmp.cpp: In function `int main(...)': tmp.cpp:5: reinterpret_cas t from `int' to `char'
I am trying to understand your program but failed. Can you tell me what you are trying to demonstrate and what the program is supposed to do? I am trying to learn.
Thanks!
I myself amn't too familiar with casts.
For example, at the moment I only use:
int j = (int)some_float ;
I'm not fully certain about :
reinterpret_cas t
dynamic_cast
static_cast
I've gone to msdn.microsoft. com looking for an explanation but I find it
hard to understand.
-JKop
JKop wrote: I myself amn't too familiar with casts.
For example, at the moment I only use:
int j = (int)some_float ;
I'm not fully certain about:
reinterpret_cas t dynamic_cast static_cast
static_cast converts between related types, such as one pointer to
another in the same class hierarchy. The conversion is compile-time checked.
reinterpret_cas t handles conversions between unrelated types.
dynamic_cast is a form of run-time checked conversion, and the type of
the object must be *polymorphic*, that is to have virtual functions.
So if in an hierarchy and you want to perform (compile-time checked)
related type conversion use static_cast.
If you want to check at runtime if the types are related use
dynamic_cast provided that the object is polymorphic.
If you want to convert between oranges and potatoes use reinterpret_cas t.
Regards,
Ioannis Vranos
JKop wrote: What ever happened to just having fun?
int main(void) { int monkeys[7] = { 3, 4 ,3, 2 ,2 ,34, 23 ,3 };
char jack reinterpret_cas t<char>(monkey s[5]);
cout << jack; }
Think calmly what are you doing.
#include <iostream>
int main(void)
{
int monkeys[7] = { 3, 4 ,3, 2 ,2 ,34, 23};
char jack=monkeys[5];
std::cout << jack;
}
Of course this will work only for the values of int that can be
represented in char.
There are people who want to mark that the above is performing an ugly
operation (which it does, implicit type conversions are a C inheritance)
you can use static_cast:
char jack=static_cas t<char>(monkey s[5]);
Regards,
Ioannis Vranos
Ioannis Vranos posted: JKop wrote:
I myself amn't too familiar with casts.
For example, at the moment I only use:
int j = (int)some_float ;
I'm not fully certain about:
reinterpret_cas t dynamic_cast static_cast static_cast converts between related types, such as one pointer to another in the same class hierarchy. The conversion is compile-time checked.
reinterpret_cas t handles conversions between unrelated types.
dynamic_cast is a form of run-time checked conversion, and the type of the object must be *polymorphic*, that is to have virtual functions.
So if in an hierarchy and you want to perform (compile-time checked) related type conversion use static_cast.
If you want to check at runtime if the types are related use dynamic_cast provided that the object is polymorphic.
If you want to convert between oranges and potatoes use reinterpret_cas t. Regards,
Ioannis Vranos
Is reinterpret_cas t stupid, by which I mean does it do any processing at
all? For example, take the following:
unsigned char jk;
reinterpret_cas t<unsigned long&>(jk) = 4000000000UL;
Will it do any truncation or anything? Or will it just try to stuff a
possibly 32-Bit value into a possibly 8-Bit space, effectively writing into
unallocated memory? If so...
Then what exactly is a "variable". Is it essentially just a chuck of
allocated memory of the size of the type which is used to define it. In my
previous example, does the compiler just take j as an address, and then just
work with in a way which is defined by the type which is used to
access/alter it?
Imagine there was no such thing as unions in C++, would the following code
work. Firstly, here's the union form of it:
union {
double double_data;
int int_data;
char char_data;
unsigned long unsigned_long_d ata;
void* void_pointer_da ta;
float* float_pointer_d ata;
}
//Now some funky code:
double recpoo;
reinterpret_cas t<float*&>(recp oo) = &some_global_fl oat;
reinterpret_cas t<unsigned long&>(recpoo) = 4000000000UL;
reinterpret_cas t<char&>(recpoo ) = 'g';
Next topic, what kind of cast is the following:
int j;
void* t = (void*)&j;
Thanks for the help!
-JKop
Ioannis Vranos posted: JKop wrote:
What ever happened to just having fun?
int main(void) { int monkeys[7] = { 3, 4 ,3, 2 ,2 ,34, 23 ,3 };
char jack reinterpret_cas t<char>(monkey s[5]);
cout << jack; } Think calmly what are you doing.
#include <iostream>
int main(void) { int monkeys[7] = { 3, 4 ,3, 2 ,2 ,34, 23};
char jack=monkeys[5];
std::cout << jack; }
Of course this will work only for the values of int that can be represented in char.
There are people who want to mark that the above is performing an ugly operation (which it does, implicit type conversions are a C inheritance) you can use static_cast:
char jack=static_cas t<char>(monkey s[5]);
Opps, that wasn't my intention, this was my intention:
int main(void)
{
int monkeys[7] = { 3, 4 ,3, 2 ,2 ,34, 23};
std::cout << reinterpret_cas t<char&>(monkey s[5]);
}
-JKop
JKop wrote: Is reinterpret_cas t stupid, by which I mean does it do any processing at all? For example, take the following:
unsigned char jk;
reinterpret_cas t<unsigned long&>(jk) = 4000000000UL;
Reinterpret_cas t performs a value conversion. It doesn't modify anything
on the implementation of jk. So the above has essentially no effect. It
is as if you had written
reinterpret_cas t<unsigned long&>(jk);
Imagine there was no such thing as unions in C++, would the following code work. Firstly, here's the union form of it:
union {
double double_data; int int_data; char char_data; unsigned long unsigned_long_d ata; void* void_pointer_da ta; float* float_pointer_d ata;
}
//Now some funky code:
double recpoo;
reinterpret_cas t<float*&>(recp oo) = &some_global_fl oat;
reinterpret_cas t<unsigned long&>(recpoo) = 4000000000UL;
reinterpret_cas t<char&>(recpoo ) = 'g';
No, reinterpret_cas t has no effect in the above.
Next topic, what kind of cast is the following:
int j;
void* t = (void*)&j;
C-style. The most unsafe.
Regards,
Ioannis Vranos
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:cb******** **@nntp1.jpl.na sa.gov... Ioannis Vranos wrote:
E. Robert Tisdale wrote:
Ioannis Vranos wrote:
E. Robert Tisdale wrote:
> There is *no* guarantee that any code will be safe and portable.
There is, for 100% ISO C++ compliant compilers.
That's a lie. No compiler developer offers such a guarantee. I still wonder. Since you like C++, why don't you participate seriously in C++ discussions?
I am serious. No one guarantees that C++ programs which comply with ANSI/ISO standards are portable -- not compiler developers and certainly not the ANSI/ISO C++ standard itself.
Yes, the standard does guarantee that compliant code
is portable to a compliant implementation. Of course
compliant implementations do not exist for all platforms.
If you write an ANSI/ISO standard compliant C++ program and claim that is ports to *any* platform,
"Any platform" would be a an impossible to make guarantee.
"Any compliant implementation" is entirely possible.
then *you* and no one else will be held legally liable if it doesn't. If you decide to make such a claim,
I've never seen such a claim.
then you had better test it on the target platform[s] first.
Of course testing is always a good idea.
But 'porting' in the context of standard C++ means
among implementations , not 'platforms'.
-Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: softwareengineer2006 |
last post by:
All Interview Questions And Answers
10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP)
I have listed over 10000 interview questions asked
in interview/placement test papers for all companies between year
2000-2005
in my website
http://www.geocities.com/allinterviewquestion/
So please have a look and make use of it.
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of
attending interviews. If you own a company best way to judge if the
candidate is worth of it.
http://www.questpond.com/InterviewRatingSheet.zip
2000 Interview questions of .NET , JAVA and SQL Server Interview
questions (worth downloading it)
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of
attending interviews. If you own a company best way to judge if the
candidate is worth of it.
http://www.questpond.com/InterviewRatingSheet.zip
|
by: connectrajesh |
last post by:
INTERVIEWINFO.NET
http://www.interviewinfo.net
FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES
NO ADVERTISEMENT
|
by: freepdfforjobs |
last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions
http://www.questpond.com/SampleInterviewQuestionBook.zip
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of
attending interviews. If you own a company best way to judge if the
candidate is worth of it.
http://www.questpond.com/InterviewRatingSheet.zip
| |
by: freesoftwarepdfs |
last post by:
Ultimate list of Interview question website.....Do not miss it
http://www.questpond.com
http://msdotnetsupport.blogspot.com/2007/01/net-interview-questions-by-dutt-part-2.html
http://msdotnetsupport.blogspot.com/2006/08/net-windows-forms-interview-questions.html
http://msdotnetsupport.blogspot.com/2006/08/net-remoting-interview-questions.html
http://msdotnetsupport.blogspot.com/2006/08/c-interview-questions.html...
|
by: ramu |
last post by:
C# Interview Questions and Answers8
http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html
C# Interview Questions and Answers7
http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers7.html
C# Interview Questions and Answers 6
http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers-6.html
C# Interview Questions and Answers 5...
|
by: reema |
last post by:
EJB Interview Questions
http://interviewdoor.com/technical/EJB-Interview-Questions.htm
CSS Interview Questions
http://interviewdoor.com/technical/CSS-Interview-Questions.htm
C Interview Questions
http://interviewdoor.com/technical/C-Interview-Questions.htm
C# Interview Questions
http://interviewdoor.com/technical/C-sharp-Interview-Questions.htm
C++ Interview Questions
http://interviewdoor.com/technical/C++-Interview-Questions.htm
|
by: reema |
last post by:
EJB Interview Questions
http://interviewdoor.com/technical/EJB-Interview-Questions.htm
CSS Interview Questions
http://interviewdoor.com/technical/CSS-Interview-Questions.htm
C Interview Questions
http://interviewdoor.com/technical/C-Interview-Questions.htm
C# Interview Questions
http://interviewdoor.com/technical/C-sharp-Interview-Questions.htm
C++ Interview Questions
http://interviewdoor.com/technical/C++-Interview-Questions.htm
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |