Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisit VLAs? #452

Closed
thomwiggers opened this issue Aug 3, 2022 · 2 comments
Closed

Revisit VLAs? #452

thomwiggers opened this issue Aug 3, 2022 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@thomwiggers
Copy link
Member

thomwiggers commented Aug 3, 2022

Variable-length arrays are kind of annoying not to have. We might extend compat.h with a macro that implements VLAs on platforms that support them, and uses alloca on platforms that don't. See also for example sphincs/sphincsplus#26.

Of course, that might be prohibitive for any applications that don't have alloca. But the way we currently work around VLAs in SPHINCS+ is extremely terrible for legibility as well.

Do we want to allow VLAs, using a macro so that they will work on MSVC?

@thomwiggers thomwiggers changed the title Revisit VLAs Revisit VLAs? Aug 3, 2022
@thomwiggers thomwiggers added the question Further information is requested label Aug 3, 2022
@dstebila
Copy link
Member

dstebila commented Aug 3, 2022

I've never seen alloca before. It looks like garbage collection? But if I understand correctly, only within the function. Will that suffice for our needs?

I'm not opposed in principle to variable length arrays, more just wanting to ensure we have something that builds on our target compilers.

@thomwiggers
Copy link
Member Author

As far as I understand, char* array = alloca(n); basically just pushes the stack pointer down in the same way that char array[n]; would do (though of course the C standard doesn't define the stack but only defines "automatic memory", so it won't phrase it as such...).

This will work for all of the desktop compiler that we target (VLAs only fail to work on MSVC) but I'm not sure about any embedded problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants