# Standard array with non-const size?

**URL:** <https://community.particle.io/t/standard-array-with-non-const-size/38836>\
**Category:** Getting Started\
**Created:** [January 19, 2018, 3:08pm UTC](https://community.particle.io/t/standard-array-with-non-const-size/38836 "2018-01-19T15:08:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlkalberer](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jlkalberer/32/20735_2.png) [@jlkalberer](https://community.particle.io/u/jlkalberer)\
**Post date:** [January 19, 2018, 3:08pm UTC](https://community.particle.io/t/standard-array-with-non-const-size/38836/1 "2018-01-19T15:08:39Z")

</div>

Hi, I’m currently in the process of getting my Particle firmware to compile on Windows so I can write unit tests. I’m basically mocking a bunch of the Particle/Arduino APIs to make it compile. I don’t actually care about making this part work as I’m writing unit tests – not integration tests.

Anyways, as I was compiling in VC++ I came upon some code in a few libraries where arrays were being created like this:

```auto
uint8_t buffer[getBufferSize(messageLength)];

```

I’m confused here. I thought you had to use `const` to set standard array sizing but these arrays are dynamically sized.

I can easily convert this code to use dynamic arrays but I prefer not to change these libraries:

```auto
int bufferSize = getBufferSize(messageLength);
uint8_t* buffer = new uint8_t[bufferSize];

```

Can someone explain why the Particle compiler doesn’t complain about the first case? Also, is there a compiler flag I can set so VC++ doesn’t care either?

Thanks

---

<div class="post-metadata">

**Author:** ![jlkalberer](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jlkalberer/32/20735_2.png) [@jlkalberer](https://community.particle.io/u/jlkalberer)\
**Post date:** [January 19, 2018, 3:16pm UTC](https://community.particle.io/t/standard-array-with-non-const-size/38836/2 "2018-01-19T15:16:11Z")

</div>

Ok, I found `Arrays of Variable Length` and how VC++ doesn’t support them. I haven’t written C/C++ in a very long time so this was new to me.

---

<div class="post-metadata">

**Author:** ![BulldogLowell](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bulldoglowell/32/4305_2.png) [@BulldogLowell](https://community.particle.io/u/BulldogLowell)\
**Post date:** [January 19, 2018, 4:39pm UTC](https://community.particle.io/t/standard-array-with-non-const-size/38836/3 "2018-01-19T16:39:12Z")

</div>

you can use `<vector>`

just be aware that you risk some fragmentation… I’ve used it in a very lightweight fashion in some of my utility libraries as well as in a broader sense, apps (i.e vector of structs), haven’t had any problems so far.

and to answer your question, it’s [a gcc thing](https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html).

---

<div class="post-metadata">

**Author:** ![jlkalberer](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jlkalberer/32/20735_2.png) [@jlkalberer](https://community.particle.io/u/jlkalberer)\
**Post date:** [January 19, 2018, 7:22pm UTC](https://community.particle.io/t/standard-array-with-non-const-size/38836/4 "2018-01-19T19:22:14Z")

</div>

Yeah… the issue is that I don’t want to modify these libraries. This code won’t work with vectors without a huge refactor and would probably be a large perf hit.

I’m trying to get gcc working with visual studio and that will solve the issue.

Thanks though
