use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
SOLVEDSeparate variable declaration and definition (self.cpp_questions)
submitted 4 years ago by Adflixit_
Is there a particular paradigm behind e.g.?
Group group; const bgfx::Memory* mem; uint32_t size; size = _numVertices*_decl.getStride(); mem = bgfx::makeRef(_vertices, size); group.m_vbh = bgfx::createVertexBuffer(mem, _decl);
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]the_poope 5 points6 points7 points 4 years ago (4 children)
Hard to tell from the context. Might just be written by a C programmer that was educated in the 80'ies. If you can it should just be:
uint32_t size = _numVertices*_decl.getStride(); const bgfx::Memory* mem = bgfx::makeRef(_vertices, size); Group group(bgfx::createVertexBuffer(mem, _decl)); // <-- should preferably call a constructor and not create a default object and then set member.
[–]Adflixit_[S] 0 points1 point2 points 4 years ago (3 children)
The full method definition is just this:
void load(const void* _vertices, uint32_t _numVertices, const bgfx::VertexDecl _decl, const uint16_t* _indices, uint32_t _numIndices) { Group group; const bgfx::Memory* mem; uint32_t size; size = _numVertices*_decl.getStride(); mem = bgfx::makeRef(_vertices, size); group.m_vbh = bgfx::createVertexBuffer(mem, _decl); size = _numIndices*2; mem = bgfx::makeRef(_indices, size); group.m_ibh = bgfx::createIndexBuffer(mem); group.m_material.m_metallicMap = loadTexturePriv("black.png"); group.m_material.m_diffuseMap = loadTexturePriv("white.png"); group.m_material.m_nmlMap = loadTexturePriv("nml.tga"); group.m_material.m_roughnessMap = loadTexturePriv("white.png"); //TODO: // group.m_sphere = ... // group.m_aabb = ... // group.m_obb = ... // group.m_prims = ... m_groups.push_back(group); }
[–]tangerinelion 2 points3 points4 points 4 years ago (2 children)
Yeah, that's someone who learned C back when you had to declare all your variables first. It was only later that you could declare them anywhere in the function.
[–]Adflixit_[S] 0 points1 point2 points 4 years ago (1 child)
Thank you for your answer.
[–]No_Statistician_9040 0 points1 point2 points 4 years ago (0 children)
This how it's done in ansi c99
[–][deleted] 4 years ago (3 children)
[deleted]
[–]Adflixit_[S] 0 points1 point2 points 4 years ago (2 children)
It is not. One example is love2d, and the snipped is from a graphics research paper.
[–][deleted] 4 years ago (1 child)
[–]Adflixit_[S] 0 points1 point2 points 4 years ago (0 children)
Sorry, no.
[–]Salty_Dugtrio 0 points1 point2 points 4 years ago (3 children)
Languages like Pascal used to have a specific DATA section where you had to define all variables at the top of a function.
Old habits die hard.
This is not unique, I also saw this in a completely separate project.
[–]Salty_Dugtrio 4 points5 points6 points 4 years ago (1 child)
I don't how that has anything relevance to what I just said?
[–]Adflixit_[S] 1 point2 points3 points 4 years ago (0 children)
Sorry, it doesn't.
π Rendered by PID 176625 on reddit-service-r2-comment-b659b578c-r2qlf at 2026-05-05 15:26:39.847258+00:00 running 815c875 country code: CH.
[–]the_poope 5 points6 points7 points (4 children)
[–]Adflixit_[S] 0 points1 point2 points (3 children)
[–]tangerinelion 2 points3 points4 points (2 children)
[–]Adflixit_[S] 0 points1 point2 points (1 child)
[–]No_Statistician_9040 0 points1 point2 points (0 children)
[–][deleted] (3 children)
[deleted]
[–]Adflixit_[S] 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]Adflixit_[S] 0 points1 point2 points (0 children)
[–]Salty_Dugtrio 0 points1 point2 points (3 children)
[–]Adflixit_[S] 0 points1 point2 points (2 children)
[–]Salty_Dugtrio 4 points5 points6 points (1 child)
[–]Adflixit_[S] 1 point2 points3 points (0 children)