Hi Im trying to learn about vtables and cache optimization in C I have a technical interview coming up and they

vector? Can I just give it vect.begin() and vect.size()?

there is none other since MSDN is considered quite good for that

You could give it &vect[0] and vect.size()*sizeof(vect[0])

Okay, that works, thanks.

thanks

actually, that may not work.

Why?

if vect is empty, the expression vect[0] yields undefined behaviour

Are you sure? I thought I was allowed to do that with defined behaviour if I take the address really fast

technically there is no problem since we're only taking the address.
however you should see issues with a debugging implementation that does bounds checking

There is no legal way to do this, then, is there?

&vec.at(0)

v; cout &v[0]; }

and let it throw if it's empty

attempt to subscript container with out-of-bounds index 0, but container only holds 0 elements.

We are trying to avoid errors, not throw them all over the palce!

oh, my mistake, I though you were trying to avoid the undefined behavior boogieman

You could just, ya know, check to see if it's size 0 before addressing. Which is what I was doing before I checked the doc link and found out that there's a function to create, not just a constructor, that can take a std

 Email Web Hosting | Email Hosting

*
To prove that you're not a bot, enter this code
Anti-Spam Image

Leave a Comment

You must be logged in to post a comment.


Blog Tags:

Similar posts: