- Failed interview test - 9 Updates
- guaranteeing const - 7 Updates
- How to create a map to insert elements based on event - 2 Updates
- own linking format - 2 Updates
- Failed interview test - 3 Updates
- /usr/include/*.h - 2 Updates
legalize+jeeves@mail.xmission.com (Richard): Nov 18 12:18AM [Please do not mail me a copy of your followup] someone@somewhere.net spake the secret code >Would anyone mind taking a look at one of these tests and the answers I >gave? I've already been passed on, and I took the name of the company >off. I asked for feedback, but they didn't bother giving me any :( OK, here's some general feedback on your responses: - code is legible with judicious use of whitespace without underdoing it or overdoing it - I didn't try it, but this looks like code that builds. You'd be amazed how many people submit code that doesn't build! - If this was a Windows shop, they won't object to VS solutions. However, if this was a Linux/Mac shop, that might turn them off (maybe they don't have a Windows machine with VS to load the solution?) If you included a CMakeLists.txt along with your generated VS solution from that, that would tell them you know CMake and understand something about adapting to different platforms - Assuming the github repo represents what you sent them, you only included the VS files that *should* be in version control. This is good as it shows that you know what files can be ignored and which ones you should keep. - There are no unit tests. To me, this is a big negative when evaluating a candidate for hire. All other things being equal, I will prefer a less experienced candidate that knows TDD over a more experienced candidate that doesn't demonstrate any knowledge of unit testing. - You did have driver code for your implementation, which is good, but it requires human observation to verify the output was correct. It proves that your code integrates properly into an executable, but it doesn't serve as an automated integration test. If you're unfamiliar with unit testing and test-driven development in C++, try my TDD workshop from C++Now! 2014: <https://github.com/boostcon/cppnow_presentations_2014/tree/master/files/test_driven> I have written a series of blog posts on TDD in C++ using VS: <https://legalizeadulthood.wordpress.com/2009/07/04/c-unit-tests-with-boost-test-part-1/> <https://legalizeadulthood.wordpress.com/2009/07/05/c-unit-tests-with-boost-test-part-2/> <https://legalizeadulthood.wordpress.com/2009/07/05/c-unit-tests-with-boost-test-part-3/> <https://legalizeadulthood.wordpress.com/2009/07/05/c-unit-tests-with-boost-test-part-4/> <https://legalizeadulthood.wordpress.com/2009/07/05/c-unit-tests-with-boost-test-part-5/> I have also written a blog post for job seekers/interviewers: <https://legalizeadulthood.wordpress.com/2015/04/21/advice-for-software-engineering-job-seekers-and-employers/> Maybe there's something useful in there for you. Every employer and interviewer is different, so I can't guarantee that the things I care about are the things they care about :-). Some things I asked every C++ programmer in an interview that most got wrong: - what's the difference between a reference and a pointer? - write the declaration for "constant pointer to constant character" -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Terminals Wiki <http://terminals-wiki.org> The Computer Graphics Museum <http://computergraphicsmuseum.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 18 01:45AM +0100 On 18.11.2016 01:18, Richard wrote: > got wrong: > - what's the difference between a reference and a pointer? > - write the declaration for "constant pointer to constant character" Is this really true? I remember at an interview once I was afraid that the interviewer wouldn't understand my use of a reference argument. Apparently at that point I had been exposed to an overwhelming number of incompetents, forming my reference for what an average developer was like. But I always thought, at least later on, that that was specific to the consulting business, and not so in software development in general? Cheers!, - Alf |
"Christopher J. Pisz" <cpisz@austin.rr.com>: Nov 17 06:55PM -0600 On 11/17/2016 6:45 PM, Alf P. Steinbach wrote: > consulting business, and not so in software development in general? > Cheers!, > - Alf I'd really hope someone applying for a senior position can tell you the difference between a reference and a pointer. This seems to be everyone's favorite question though. They asked me that as well. I told them one was an amperstand and one was a shiny star. After a second pause, I told them: ) That a reference is an alias, while a pointer is a value that is a memory location. ) You can i perform arithmetic on a pointer, while you cannot on a reference ) You can assign NULL to a pointer, while a reference should never be NULL |
Gareth Owen <gwowen@gmail.com>: Nov 18 09:28AM > The question was about "/the/ difference", the answers are > /several/ differences. So, they do not answer the question > about /the/ difference. I hope my employers would never employ anyone who started their answer like that. If you think conversational English should be interpreted like a programming language, you would be a nightmare to work with. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Nov 18 10:29AM +0100 On 18.11.2016 02:43, Stefan Ram wrote: > The question was about "/the/ difference", the answers are > /several/ differences. So, they do not answer the question > about /the/ difference. "The difference" is just a common expression. If an interviewer insists that it means a single difference, then either the guy is stupid, or he's (dishonestly) treating you like you're stupid, having you on. In either case say goodbye to that firm. > type (involving »&VARNAME« or »&&VARNAME« or equivalent). > But only »decltype« can sense this afterwards. > A pointer is an object whose expression has pointer type. In standardeese a "variable" is a named "object". For completeness: an object is a region of storage, with an associated type. And a region of storage needs not be contiguous. Main example: diamond inheritance. But functions can return references, i.e. unnamed references, so it's not the case that a reference is necessarily formally a variable. > A reference usually /is/ a memory location. Proof: one > usually can take its address: > int i; int & r = i; escape( &r ); /* &i==&r BTW */ A reference always refers to a memory location in the "as if" sense. You can always take the address. > . One /can/ perform arithmetics on a reference sometimes: > int i {}; int & r = i; escape( r + 1 ); This is not arithmetic on the reference: it's arithmetic on what the reference refers to. There is no reference arithmetic in the language. > . nullptr /can/ be assigned to a reference sometimes > int * i; int * & r = i; r = nullptr; escape( r ); /* !r */ Ditto, this is not assignment of a nullpointer to a reference: it's a assignment to what the reference refers to. A reference can't itself be null in a valid program. It can be null with Undefined Behavior, by dereferencing a nullpointer, but, because of the UB, you can't reliably detect that. > . (I can't use a compiler right now, so all of the above > is untested and IIRC.) Uhm, it's not clear what you meant with the `escape`. Cheers & hth., - Alf |
asetofsymbols@gmail.com: Nov 18 02:26AM -0800 Difference from reference and pointer? Pointers read write the memory use '*' instead reference not. Reference are useful for write argument for C++ operators because what is passed is not the value but in practices a pointer This is because operators can not have their arguments pointers at Last I remember so Is it possible doing +(int*, int*)? What about a language where all objects are references? type a, b; a and b are one address that contain the type returned from &a and &b a and b their value returned from a, b when pass a to a function it is an address... |
JiiPee <no@notvalid.com>: Nov 18 04:18PM > a and b are one address that contain the type returned from &a and &b > a and b their value returned from a, b > when pass a to a function it is an address... I personally hate that (that there is no deep copy by default). I think Java, or was is javasript, did that... and i Had nightmares to work with that... becouse sometimes I wanted a normal copy and its difficult there. I just like how C++ does it.. its logical that a = b mean full copy and not a pointer or reference copy by default, becouse thats what I am expecting to get. |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Nov 18 05:33PM On 18/11/2016 10:20, Stefan Ram wrote: > reference or object.«. So above, the name »r« > denotes the reference. So, in »r + 1«, »r« denotes > the reference, and arithmetics is done on it. No. The arithmetic is being done on what the reference refers to. There is pointer arithmetic but there is no such thing as reference arithmetic. /Flibble |
legalize+jeeves@mail.xmission.com (Richard): Nov 18 09:01PM [Please do not mail me a copy of your followup] "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> spake the secret code >> - what's the difference between a reference and a pointer? >> - write the declaration for "constant pointer to constant character" >Is this really true? Over a period of 4+ years I interviewed quite a few people and this was the case with the people I interviewed. However, the job market is tight here and recruiters tell me "if you want good talent, you have to steal it from another company". Most of the people I interviewed were in the early part of their career and while some people answered these questions, most people failed. Re: difference between reference and pointer, all I wanted to hear them say is "references can't be null". To me, that's the important part to understand, and that's the part they missed. The same ones that missed that generally fumbled with the syntax as well. Maybe lots of people just think 'C++ is C with classes' and don't dig any further into it, or maybe the good people just needed to be poached from other companies instead of approaching us when we had an opening. Or maybe our manager just sucked ass (he did). -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Terminals Wiki <http://terminals-wiki.org> The Computer Graphics Museum <http://computergraphicsmuseum.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
Popping mad <rainbow@colition.gov>: Nov 18 06:39PM How does one do this without losing the const }; /* constructor */ Node ( const Node &other ){ parent(other.parent()) const; right(other.right() const); left(other.left() const); value(other.value() const); max(other.max()) const; }; /* copy constructor */ ~Node (){}; /* destructor */ msort.h|41 col 25| error: passing 'const maxpath::Node' as 'this' argument discards qualifiers [-fpermissive] |
bitrex <bitrex@de.lete.earthlink.net>: Nov 18 03:06PM -0500 On 11/18/2016 01:39 PM, Popping mad wrote: > destructor */ > msort.h|41 col 25| error: passing 'const maxpath::Node' as 'this' > argument discards qualifiers [-fpermissive] Probably because your methods "parent", "right", etc. aren't declared "const." What compiler does this compile under? I'm surprised putting "const" after a function call like that isn't a syntax error. If you have to do it this way probably best to create a local non-const copy of Node in the copy ctr and pass it in |
bitrex <bitrex@de.lete.earthlink.net>: Nov 18 03:13PM -0500 On 11/18/2016 03:06 PM, bitrex wrote: > after a function call like that isn't a syntax error. > If you have to do it this way probably best to create a local non-const > copy of Node in the copy ctr and pass it in Well, wait. That might be bad... |
red floyd <no.spam.here@its.invalid>: Nov 18 12:14PM -0800 On 11/18/2016 12:06 PM, bitrex wrote: > after a function call like that isn't a syntax error. > If you have to do it this way probably best to create a local non-const > copy of Node in the copy ctr and pass it in I *THINK* he's trying to use an initializer list. I've already told him his syntax for that is wrong. |
bitrex <bitrex@de.lete.earthlink.net>: Nov 18 03:16PM -0500 On 11/18/2016 03:14 PM, red floyd wrote: |
bitrex <bitrex@de.lete.earthlink.net>: Nov 18 03:17PM -0500 On 11/18/2016 03:14 PM, red floyd wrote: >> copy of Node in the copy ctr and pass it in > I *THINK* he's trying to use an initializer list. I've already told him > his syntax for that is wrong. Ah. I would be pretty surprised if the code as it is right there actually compiled... |
bitrex <bitrex@de.lete.earthlink.net>: Nov 18 03:23PM -0500 On 11/18/2016 03:14 PM, red floyd wrote: >> copy of Node in the copy ctr and pass it in > I *THINK* he's trying to use an initializer list. I've already told him > his syntax for that is wrong. if what he's shooting for is something like: Node(const Node& other) : parent(other.parent()), right(other.right()), etc. then AFAIK the "getters" parent, right etc. need to have "const" after their function declaration or there's gonna be trouble. |
Ben Bacarisse <ben.usenet@bsb.me.uk>: Nov 18 01:41AM > Thanks Ben. I am actually new to C++. The distance is a double data > type and the Vehicle and Pedestrian ID are integers. Is it possible > with vectors? Yes. > Then pedestrian:1 calculates its distance from vehicle:1 > Event#6 at time t6: Pedestrian_ID:2 receives a message from Vehicle_ID:1 > Then pedestrian:2 calculates its distance from vehicle:1 The talk of time and events is confusing to me. To me, pedestrians and vehicles are moving objects so this data may be changing over time. But if time is not a factor, you have a very simple problem: an n_p by n_v matrix of distances. The times (and events) at which this data is known are not really significant, although I still don't know if you will always have full data -- all the vehicle/pedestrian distances. > I have to find which pedestrian has the minimum distance from Vehicle:0 > and which pedestrian has the minimum distance from Vehicle:1 You need to think about a tie as well. The minimum distance may be the same for two or more pedestrians or vehicles. It's obvious what you'll need to do but don't forget about it. > Then I need to send(broadcast) this information to all the > pedestrians. That will need clarifying. In particular, you probably don't want to send all the data to all the pedestrians. > So I need a way to store the information at each event and increment > it at next event and finally based on the information, find the > minimum distance for each vehicle. I'm having trouble understanding what the problem is. You say you are new to C++, but how would you do it in whatever language you know best? What part of C++ is the barrier to translating that code into C++? Depending on my understanding of some of the details above, all you are asking is how to record a distance d between vehicle v and pedestrian p. That's not much more complex than distance[v][p] = d; -- Ben. |
Shivu <rout.jyoti@gmail.com>: Nov 18 12:00PM -0800 On Friday, November 18, 2016 at 2:41:45 AM UTC+1, Ben Bacarisse wrote: > distance[v][p] = d; > -- > Ben. Thank you Ben. The problem I am facing is, to get the data for all the pedestrians at single point of time. I am receiving them at different time. The vehicles and pedestrians change their positions but its after a certain amount of time, lets say 5 seconds. I want to do this calculation within that time. This procedure would repeat every 5 seconds when they change their positions. So I need a container to hold the data for each pedestrian at each event and could able to append the next entries to the container for the next pedestrians in the next events. Thanks |
Prroffessorr Fir Kenobi <profesor.fir@gmail.com>: Nov 18 09:19AM -0800 i consider making my own linking format (equivalent for .o/obj ) i think it would be cleaner to work on my own improved one then making the converter for windows ones i am not asking if this is good idea becouse i think nearly everybody will say this is bad idea - making yet another .obj format :: but it has an adventage my ovn may be clearer and it could be more pleasurable to work on it (finally after making it all i could eventually get rid of it) the question is how it should look like, as i said in another thread i could use some easy convention to deniote blocks in file, 32 bit would be 4 ascii characters for making block signature then next 32 bit would be its size, like 'head', 200, {192 bytes of header block} 'text', 3000, {2992 bytes of function bodies} 'data', 400, {392 bytes of preinitialised data} 'bss ', 100, {92 bytes of static empty arrays descriptions* } 'relo', 700, {692 bytes of relocation data} //?? 'expo', 200, {192 bytes of export data} //?? 'impo', 200, {192 bytes of import data} // ?? * im not quite sure how linkers store it, as an array of consecyutive sizes, like {40000, 10000, 1000000} - it would mean 3 static arrays of given sizes? the question is what is absolutely needed and what can be skipped to make this format totally defined but much clear, i would like to produce this as my own c2 compiler/a2 assembler output (which will be in a role od static .o module which then by my other tool would be converted for mingw compatible .o (32 bit, win mainly designed to be linked with winapi environment) some thoughts? those 'relo','expo', and 'impo' parts are most obscure by now to me (i must need to know what exactly putt there and how - some vision?) i will think and read on this but some side hints could be helpfull maybe |
scott@slp53.sl.home (Scott Lurndal): Nov 18 05:55PM >i consider making my own linking format (equivalent for .o/obj ) >i think it would be cleaner to work on my own improved one then >making the converter for windows ones Don't reinvent the wheel. https://en.wikipedia.org/wiki/Executable_and_Linkable_Format |
ram@zedat.fu-berlin.de (Stefan Ram): Nov 18 01:43AM >memory location. >) You can i perform arithmetic on a pointer, while you cannot on a reference >) You can assign NULL to a pointer, while a reference should never be NULL The question was about "/the/ difference", the answers are /several/ differences. So, they do not answer the question about /the/ difference. A reference is a variable that was declared as a reference type (involving »&VARNAME« or »&&VARNAME« or equivalent). But only »decltype« can sense this afterwards. A pointer is an object whose expression has pointer type. A reference usually /is/ a memory location. Proof: one usually can take its address: int i; int & r = i; escape( &r ); /* &i==&r BTW */ . One /can/ perform arithmetics on a reference sometimes: int i {}; int & r = i; escape( r + 1 ); . nullptr /can/ be assigned to a reference sometimes int * i; int * & r = i; r = nullptr; escape( r ); /* !r */ . (I can't use a compiler right now, so all of the above is untested and IIRC.) |
ram@zedat.fu-berlin.de (Stefan Ram): Nov 18 08:45AM >>>> - what's the difference between a reference and a pointer? ... >int * i; int * & r = i; r = nullptr; escape( r ); /* !r */ When r is a reference and i is a pointer (as declared above), the difference is given by the expression (r-i) whenever it is defined. I thing with the declarations from above, it should be ((ptrdiff_t)0). |
ram@zedat.fu-berlin.de (Stefan Ram): Nov 18 10:20AM >On 18.11.2016 02:43, Stefan Ram wrote: >''The difference'' is just a common expression. If an interviewer insists Sorry, that's my own problem with this wording. I would prefer the wording »Which differences between A and B do you know?«, or even better: »What is A, and what is B?«. For example, you can ask someone »What is the moon? What is the statue of liberty?« and he might easily answer both questions, showing that he knows both concepts well. But »What is the difference between the moon and the statue of liberty?« might needlessly create more difficulties. So, I'd prefer, »What is a pointer? What is a reference?«. >>But only »decltype« can sense this afterwards. >>A pointer is an object whose expression has pointer type. >In standardeese a ''variable'' is a named ''object''. Possibly I should not have used »variable« but »expression« since functions also might have a reference type as return type. Speaking of the standard. Here is the wording right from the li^H^Hstandard's mouth: |A variable is introduced by the declaration of a reference |other than a non-static data member or of an object. |The variable's name, if any, denotes the reference or |object. 3p6 In my teaching I do /not/ want to emphasize a contrast between /references/ and /objects/, but rather between /reference initialization/ and /object initialization/. An /object initialization of a variable/ will create (under certain cirumstances) a new object and a name for it. A /reference initialization of a variable/ will create a new name for an object that already exists. But after the initialization the two kinds of names often cannot be distinguished anymore, with the exception of a »decltype« context. And it also matters that (rvalue) reference types might matter in overload resolution. >But functions can return references, i.e. unnamed references, so it's >not the case that a reference is necessarily formally a variable. Yes, thank you. I also now have expressed the same thought above. >> int i {}; int & r = i; escape( r + 1 ); >This is not arithmetic on the reference: it's arithmetic on what the >reference refers to. 3p6 said »The variable's name, if any, denotes the reference or object.«. So above, the name »r« denotes the reference. So, in »r + 1«, »r« denotes the reference, and arithmetics is done on it. Sometimes, it is very difficult to be clear and unambiguous in descriptive words without examples, and we humans need to use examples. I think the authors of the standard also have understood this and now provide many examples, possibly more than in older versions of the standard. >Uhm, it's not clear what you meant with the -escape-. I just wanted to express that the argument expression »...« in »escape( ... )« can now be used as an argument expression in a function call (its value now might escape the scope), and wanted to direct the readers attention towards this expression. The name »escape« came from too much exposure to Chandler Carruth videos, I should have used »example« or »use« instead. |
woodbrian77@gmail.com: Nov 17 05:51PM -0800 On Thursday, November 17, 2016 at 4:58:11 PM UTC-6, Richard wrote: > >#include <czlib> > These style of includes, e.g. <cstdlib>, are special include file > names specified by the ISO C++ standard. I'm not able to recall who it was that made this point previously, but someone here said that those special names are a hindrance in terms of searching. In general I'm not an advocate of uniformity, but having multiple forms for the names of headers makes it harder to find things. And if I remember right, Alf advocated against using those parallel headers that start with a 'c', like <cstdio>. I think he considered them to be a failed experiment. Brian Ebenezer Enterprises - In G-d we trust. http://webEbenezer.net |
Robert Wessel <robertwessel2@yahoo.com>: Nov 17 08:20PM -0600 >And if I remember right, Alf advocated against using those >parallel headers that start with a 'c', like <cstdio>. >I think he considered them to be a failed experiment. I'm not sure what searching issues are involved, usually the c* headers are just a fairly thin wrapper around the *.h headers. There are some namespace differences, which usually results in a small amount of code in the c* version. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment