Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>_Groups = (group **) new char[sizeof (group **) * NOMGRPS]; </code></pre> <p>This creates enough space for <code>NOMGRPS</code> group pointers and casts it to a pointer to a <code>group**</code>, presumably to be used as an array of pointers to objects of type <code>group</code> that are allocated elsewhere. This is (or more strictly speaking, was) a common idiom as <code>char</code> is almost always a single byte, so this says "Allocate <code>sizeof (group **) * NOMGRPS</code> bytes (enough bytes for <code>NOMGRPS</code> group pointers) and cast it to a pointer to a group pointer. So if <code>NOMGRPS</code> is 10, and you are on a 32 bit system, with 4 byte pointers, this allocates 40 bytes.</p> <pre><code>_Groups = new group*[sizeof (group **) * NOMGRPS]; </code></pre> <p>Here instead of saying you want 40 <code>char</code>s (i.e. bytes) you are saying you want 40 <code>group*</code>. So if <code>NOMGRPS</code> is 10, and you are on a 32 bit system, with 4 byte pointers, this allocates 40 * 4 or 160 bytes. This is almost certainly not what you want, but since it overallocates memory, it will likely work fine. Your instincts to make this change are right. Any time you cast in modern C++, you should consider it suspect. But you didn't quite go far enough.</p> <p>What you really want is this:</p> <pre><code>_Groups = new group*[NOMGRPS]; </code></pre> <p><code>new</code> knows the size of a <code>group*</code> and thus will allocate enough for <code>NOMGRPS</code> of them. This is more correct than the original version which used <code>new char</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload