GCC; Hint compiler that variable is initialized;












1















There is a part of code:



void func0(xxx* obj)
{
void* ptr;
size_t size;
obj->getBuffer(ptr, size); // Init ptr & size

while(size) // ERROR: may be used uninitialized
{
// processing buffer
}
}


'xxx.h'



#include <cstddef>

class xxx
{
public:
xxx();
xxx(void* p, size_t s);
void getBuf(void*& p, size_t& s);
private:
void* pp;
size_t ss;
};



'xxx.cpp'



#include "xxx.h"

xxx::xxx()
{
pp = (void*)0xFFFF;
ss = 0x100;
}

xxx::xxx(void* p, size_t s)
{
pp = p;
ss = s;
}

void xxx::getBuf(void*& p, size_t& s)
{
p = pp;
s = ss;
}




GCC generates 'may be used uninitialized in this function' error.



GCC version: 'aarch64-elf-g++ (GNU Toolchain for the A-profile Architecture 8.2-2018-08 (arm-rel-8.23)) 8.2.1 20180802'




Is there a way to hint compiler that variables are actually inited without explicitly assign them with some default values in declaration?



PS: Error comes with a new version of toolchain.

please no 'rewrite everything' / 'bad design' advices.










share|improve this question

























  • Possible duplicate of Disable GCC "may be used uninitialized" on a particular variable

    – Swordfish
    Nov 21 '18 at 4:16











  • not exactly, my question. I'm interesting in changing getBuffer attributes. For example, for now getBuffer assigns variables always. Lets say it's modified and skips initialization of a parameter. "-Wuninitialized" would suppress a warning, while variable is indeed uninited. Additional inconvenience of this way that getBuffer is used in different files, all these files should be modified. Changing multiple files, rather than only one, is exactly what I want to avoid.

    – user3124812
    Nov 21 '18 at 4:39











  • Cannot reproduce. Please provide a Minimal, Complete, and Verifiable example.

    – Passer By
    Nov 21 '18 at 4:50











  • @PasserBy Those pieces of code should be in different compilation units. Is there an online tool which allow to create a few files? 'godbolt' and similar work with only one 'main' file and compiler effectively inline everything...

    – user3124812
    Nov 21 '18 at 5:55











  • wandbox.org. Your question is required to make sense without an external link, please edit the question to be a Minimal, Complete, and Verifiable example.

    – Passer By
    Nov 21 '18 at 6:12


















1















There is a part of code:



void func0(xxx* obj)
{
void* ptr;
size_t size;
obj->getBuffer(ptr, size); // Init ptr & size

while(size) // ERROR: may be used uninitialized
{
// processing buffer
}
}


'xxx.h'



#include <cstddef>

class xxx
{
public:
xxx();
xxx(void* p, size_t s);
void getBuf(void*& p, size_t& s);
private:
void* pp;
size_t ss;
};



'xxx.cpp'



#include "xxx.h"

xxx::xxx()
{
pp = (void*)0xFFFF;
ss = 0x100;
}

xxx::xxx(void* p, size_t s)
{
pp = p;
ss = s;
}

void xxx::getBuf(void*& p, size_t& s)
{
p = pp;
s = ss;
}




GCC generates 'may be used uninitialized in this function' error.



GCC version: 'aarch64-elf-g++ (GNU Toolchain for the A-profile Architecture 8.2-2018-08 (arm-rel-8.23)) 8.2.1 20180802'




Is there a way to hint compiler that variables are actually inited without explicitly assign them with some default values in declaration?



PS: Error comes with a new version of toolchain.

please no 'rewrite everything' / 'bad design' advices.










share|improve this question

























  • Possible duplicate of Disable GCC "may be used uninitialized" on a particular variable

    – Swordfish
    Nov 21 '18 at 4:16











  • not exactly, my question. I'm interesting in changing getBuffer attributes. For example, for now getBuffer assigns variables always. Lets say it's modified and skips initialization of a parameter. "-Wuninitialized" would suppress a warning, while variable is indeed uninited. Additional inconvenience of this way that getBuffer is used in different files, all these files should be modified. Changing multiple files, rather than only one, is exactly what I want to avoid.

    – user3124812
    Nov 21 '18 at 4:39











  • Cannot reproduce. Please provide a Minimal, Complete, and Verifiable example.

    – Passer By
    Nov 21 '18 at 4:50











  • @PasserBy Those pieces of code should be in different compilation units. Is there an online tool which allow to create a few files? 'godbolt' and similar work with only one 'main' file and compiler effectively inline everything...

    – user3124812
    Nov 21 '18 at 5:55











  • wandbox.org. Your question is required to make sense without an external link, please edit the question to be a Minimal, Complete, and Verifiable example.

    – Passer By
    Nov 21 '18 at 6:12
















1












1








1


1






There is a part of code:



void func0(xxx* obj)
{
void* ptr;
size_t size;
obj->getBuffer(ptr, size); // Init ptr & size

while(size) // ERROR: may be used uninitialized
{
// processing buffer
}
}


'xxx.h'



#include <cstddef>

class xxx
{
public:
xxx();
xxx(void* p, size_t s);
void getBuf(void*& p, size_t& s);
private:
void* pp;
size_t ss;
};



'xxx.cpp'



#include "xxx.h"

xxx::xxx()
{
pp = (void*)0xFFFF;
ss = 0x100;
}

xxx::xxx(void* p, size_t s)
{
pp = p;
ss = s;
}

void xxx::getBuf(void*& p, size_t& s)
{
p = pp;
s = ss;
}




GCC generates 'may be used uninitialized in this function' error.



GCC version: 'aarch64-elf-g++ (GNU Toolchain for the A-profile Architecture 8.2-2018-08 (arm-rel-8.23)) 8.2.1 20180802'




Is there a way to hint compiler that variables are actually inited without explicitly assign them with some default values in declaration?



PS: Error comes with a new version of toolchain.

please no 'rewrite everything' / 'bad design' advices.










share|improve this question
















There is a part of code:



void func0(xxx* obj)
{
void* ptr;
size_t size;
obj->getBuffer(ptr, size); // Init ptr & size

while(size) // ERROR: may be used uninitialized
{
// processing buffer
}
}


'xxx.h'



#include <cstddef>

class xxx
{
public:
xxx();
xxx(void* p, size_t s);
void getBuf(void*& p, size_t& s);
private:
void* pp;
size_t ss;
};



'xxx.cpp'



#include "xxx.h"

xxx::xxx()
{
pp = (void*)0xFFFF;
ss = 0x100;
}

xxx::xxx(void* p, size_t s)
{
pp = p;
ss = s;
}

void xxx::getBuf(void*& p, size_t& s)
{
p = pp;
s = ss;
}




GCC generates 'may be used uninitialized in this function' error.



GCC version: 'aarch64-elf-g++ (GNU Toolchain for the A-profile Architecture 8.2-2018-08 (arm-rel-8.23)) 8.2.1 20180802'




Is there a way to hint compiler that variables are actually inited without explicitly assign them with some default values in declaration?



PS: Error comes with a new version of toolchain.

please no 'rewrite everything' / 'bad design' advices.







c++ gcc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 0:44







user3124812

















asked Nov 21 '18 at 4:14









user3124812user3124812

4241517




4241517













  • Possible duplicate of Disable GCC "may be used uninitialized" on a particular variable

    – Swordfish
    Nov 21 '18 at 4:16











  • not exactly, my question. I'm interesting in changing getBuffer attributes. For example, for now getBuffer assigns variables always. Lets say it's modified and skips initialization of a parameter. "-Wuninitialized" would suppress a warning, while variable is indeed uninited. Additional inconvenience of this way that getBuffer is used in different files, all these files should be modified. Changing multiple files, rather than only one, is exactly what I want to avoid.

    – user3124812
    Nov 21 '18 at 4:39











  • Cannot reproduce. Please provide a Minimal, Complete, and Verifiable example.

    – Passer By
    Nov 21 '18 at 4:50











  • @PasserBy Those pieces of code should be in different compilation units. Is there an online tool which allow to create a few files? 'godbolt' and similar work with only one 'main' file and compiler effectively inline everything...

    – user3124812
    Nov 21 '18 at 5:55











  • wandbox.org. Your question is required to make sense without an external link, please edit the question to be a Minimal, Complete, and Verifiable example.

    – Passer By
    Nov 21 '18 at 6:12





















  • Possible duplicate of Disable GCC "may be used uninitialized" on a particular variable

    – Swordfish
    Nov 21 '18 at 4:16











  • not exactly, my question. I'm interesting in changing getBuffer attributes. For example, for now getBuffer assigns variables always. Lets say it's modified and skips initialization of a parameter. "-Wuninitialized" would suppress a warning, while variable is indeed uninited. Additional inconvenience of this way that getBuffer is used in different files, all these files should be modified. Changing multiple files, rather than only one, is exactly what I want to avoid.

    – user3124812
    Nov 21 '18 at 4:39











  • Cannot reproduce. Please provide a Minimal, Complete, and Verifiable example.

    – Passer By
    Nov 21 '18 at 4:50











  • @PasserBy Those pieces of code should be in different compilation units. Is there an online tool which allow to create a few files? 'godbolt' and similar work with only one 'main' file and compiler effectively inline everything...

    – user3124812
    Nov 21 '18 at 5:55











  • wandbox.org. Your question is required to make sense without an external link, please edit the question to be a Minimal, Complete, and Verifiable example.

    – Passer By
    Nov 21 '18 at 6:12



















Possible duplicate of Disable GCC "may be used uninitialized" on a particular variable

– Swordfish
Nov 21 '18 at 4:16





Possible duplicate of Disable GCC "may be used uninitialized" on a particular variable

– Swordfish
Nov 21 '18 at 4:16













not exactly, my question. I'm interesting in changing getBuffer attributes. For example, for now getBuffer assigns variables always. Lets say it's modified and skips initialization of a parameter. "-Wuninitialized" would suppress a warning, while variable is indeed uninited. Additional inconvenience of this way that getBuffer is used in different files, all these files should be modified. Changing multiple files, rather than only one, is exactly what I want to avoid.

– user3124812
Nov 21 '18 at 4:39





not exactly, my question. I'm interesting in changing getBuffer attributes. For example, for now getBuffer assigns variables always. Lets say it's modified and skips initialization of a parameter. "-Wuninitialized" would suppress a warning, while variable is indeed uninited. Additional inconvenience of this way that getBuffer is used in different files, all these files should be modified. Changing multiple files, rather than only one, is exactly what I want to avoid.

– user3124812
Nov 21 '18 at 4:39













Cannot reproduce. Please provide a Minimal, Complete, and Verifiable example.

– Passer By
Nov 21 '18 at 4:50





Cannot reproduce. Please provide a Minimal, Complete, and Verifiable example.

– Passer By
Nov 21 '18 at 4:50













@PasserBy Those pieces of code should be in different compilation units. Is there an online tool which allow to create a few files? 'godbolt' and similar work with only one 'main' file and compiler effectively inline everything...

– user3124812
Nov 21 '18 at 5:55





@PasserBy Those pieces of code should be in different compilation units. Is there an online tool which allow to create a few files? 'godbolt' and similar work with only one 'main' file and compiler effectively inline everything...

– user3124812
Nov 21 '18 at 5:55













wandbox.org. Your question is required to make sense without an external link, please edit the question to be a Minimal, Complete, and Verifiable example.

– Passer By
Nov 21 '18 at 6:12







wandbox.org. Your question is required to make sense without an external link, please edit the question to be a Minimal, Complete, and Verifiable example.

– Passer By
Nov 21 '18 at 6:12














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405165%2fgcc-hint-compiler-that-variable-is-initialized%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405165%2fgcc-hint-compiler-that-variable-is-initialized%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)