Pointers in C Programming by Thomas Mailund

Pointers in C Programming by Thomas Mailund

Author:Thomas Mailund
Language: eng
Format: epub
ISBN: 9781484269275
Publisher: Apress


The growth function will check that we are allocating more space and give us an error otherwise. It prevents, among other things, that we try to grow the maximal size of a buffer. Otherwise, it is similar to what we saw for dynamic arrays. We allocate a new buffer, and if it fails, we report an error. Otherwise, we update the gapped buffer. First, we move the data at the end of the buffer to the new position, and then we update the size and gap_end position. We do it in the opposite order, though, because the gb_back() macro we use to get the number of characters after the gap depends on the size, so we cannot update the size first.bool grow_buffer(struct gap_buf *buf, size_t new_size)

{

// We cannot grow to a smaller (or equal) size

if (buf->size >= new_size) return false;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.