<p></p>
<p><a class="user-mention" data-hovercard-type="user" data-hovercard-url="/users/b4n/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/b4n">@b4n</a>, yes, but std::vector is a library type, not a builtin, which keeps track of its size and its capacity (which is why it is possible to insert the assert, its has size to compare to, but in C since nothing saves the size of array you malloced no automatic assert can be inserted in an index operation).  Operator[] on a std::vector is not a builtin, its an overloaded operator member function that returns a reference to the indexed member.  So your <code>&vector[0]</code> has to call <code>vector.operator[](0)</code> before taking the address of the referenced object when it returns.  But of course you can't reference a non-existent object, which is why its UB to do so.</p>
<p>The std::vector has an alternative member function <code>vector.at()</code> that is always checked and which throws an exception if the index is out of range.  But of course thats slower, whereas operator[] is as fast as C, so all premature optimisers (basically all programmers :) use it.</p>
<p>As I keep saying C++ is not C <g-emoji class="g-emoji" alias="grin" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f601.png">😁</g-emoji></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany-plugins/issues/1041#issuecomment-739907326">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAIOWJ5K4UAKELUPRK4X7CTSTTHSLANCNFSM4UHMIKQQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AAIOWJ6L2M7WGMBFR3BFN5LSTTHSLA5CNFSM4UHMIKQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFQNBN7Q.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/geany/geany-plugins/issues/1041#issuecomment-739907326",
"url": "https://github.com/geany/geany-plugins/issues/1041#issuecomment-739907326",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>