Solidity ParseError with null












1















mapping (address => uint) itemsPerCreator;

if (itemsPerCreator[_creator] == null){}



Remix give me a error: ParseError: Expected primary expression.




_creator is a addres type variable. Inside the mapping each addres have a uint value.










share|improve this question

























  • What is null?

    – goodvibration
    Dec 26 '18 at 9:28













  • The if is inside a function. So I´m trying to evaluate if is a value inside the mapping. That mapping have one a address and a uint value. So im evaluating if the value inside the mapping is null

    – Eduardo
    Dec 26 '18 at 9:29











  • It doesn't answer my question - where have you declared a uint variable named null?

    – goodvibration
    Dec 26 '18 at 9:30













  • null is not a variable. Is a value

    – Eduardo
    Dec 26 '18 at 9:31






  • 1





    Any unmapped value is actually mapped to the zero value of the given type, which in your case is uint(0), or simply 0.

    – goodvibration
    Dec 26 '18 at 9:50


















1















mapping (address => uint) itemsPerCreator;

if (itemsPerCreator[_creator] == null){}



Remix give me a error: ParseError: Expected primary expression.




_creator is a addres type variable. Inside the mapping each addres have a uint value.










share|improve this question

























  • What is null?

    – goodvibration
    Dec 26 '18 at 9:28













  • The if is inside a function. So I´m trying to evaluate if is a value inside the mapping. That mapping have one a address and a uint value. So im evaluating if the value inside the mapping is null

    – Eduardo
    Dec 26 '18 at 9:29











  • It doesn't answer my question - where have you declared a uint variable named null?

    – goodvibration
    Dec 26 '18 at 9:30













  • null is not a variable. Is a value

    – Eduardo
    Dec 26 '18 at 9:31






  • 1





    Any unmapped value is actually mapped to the zero value of the given type, which in your case is uint(0), or simply 0.

    – goodvibration
    Dec 26 '18 at 9:50
















1












1








1








mapping (address => uint) itemsPerCreator;

if (itemsPerCreator[_creator] == null){}



Remix give me a error: ParseError: Expected primary expression.




_creator is a addres type variable. Inside the mapping each addres have a uint value.










share|improve this question
















mapping (address => uint) itemsPerCreator;

if (itemsPerCreator[_creator] == null){}



Remix give me a error: ParseError: Expected primary expression.




_creator is a addres type variable. Inside the mapping each addres have a uint value.







solidity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 26 '18 at 11:14







Eduardo

















asked Dec 26 '18 at 9:16









EduardoEduardo

2438




2438













  • What is null?

    – goodvibration
    Dec 26 '18 at 9:28













  • The if is inside a function. So I´m trying to evaluate if is a value inside the mapping. That mapping have one a address and a uint value. So im evaluating if the value inside the mapping is null

    – Eduardo
    Dec 26 '18 at 9:29











  • It doesn't answer my question - where have you declared a uint variable named null?

    – goodvibration
    Dec 26 '18 at 9:30













  • null is not a variable. Is a value

    – Eduardo
    Dec 26 '18 at 9:31






  • 1





    Any unmapped value is actually mapped to the zero value of the given type, which in your case is uint(0), or simply 0.

    – goodvibration
    Dec 26 '18 at 9:50





















  • What is null?

    – goodvibration
    Dec 26 '18 at 9:28













  • The if is inside a function. So I´m trying to evaluate if is a value inside the mapping. That mapping have one a address and a uint value. So im evaluating if the value inside the mapping is null

    – Eduardo
    Dec 26 '18 at 9:29











  • It doesn't answer my question - where have you declared a uint variable named null?

    – goodvibration
    Dec 26 '18 at 9:30













  • null is not a variable. Is a value

    – Eduardo
    Dec 26 '18 at 9:31






  • 1





    Any unmapped value is actually mapped to the zero value of the given type, which in your case is uint(0), or simply 0.

    – goodvibration
    Dec 26 '18 at 9:50



















What is null?

– goodvibration
Dec 26 '18 at 9:28







What is null?

– goodvibration
Dec 26 '18 at 9:28















The if is inside a function. So I´m trying to evaluate if is a value inside the mapping. That mapping have one a address and a uint value. So im evaluating if the value inside the mapping is null

– Eduardo
Dec 26 '18 at 9:29





The if is inside a function. So I´m trying to evaluate if is a value inside the mapping. That mapping have one a address and a uint value. So im evaluating if the value inside the mapping is null

– Eduardo
Dec 26 '18 at 9:29













It doesn't answer my question - where have you declared a uint variable named null?

– goodvibration
Dec 26 '18 at 9:30







It doesn't answer my question - where have you declared a uint variable named null?

– goodvibration
Dec 26 '18 at 9:30















null is not a variable. Is a value

– Eduardo
Dec 26 '18 at 9:31





null is not a variable. Is a value

– Eduardo
Dec 26 '18 at 9:31




1




1





Any unmapped value is actually mapped to the zero value of the given type, which in your case is uint(0), or simply 0.

– goodvibration
Dec 26 '18 at 9:50







Any unmapped value is actually mapped to the zero value of the given type, which in your case is uint(0), or simply 0.

– goodvibration
Dec 26 '18 at 9:50












1 Answer
1






active

oldest

votes


















1














You are getting this error because there is nothing like null or undefined in solidity. An uint initializes with 0.



So, to check the zero-state of value(either default or intentionally updated) to the corresponding key in your mapping, you should write it as:



if (itemsPerCreator[_creator] == 0){}


As per the Solidity documentation:




A variable which is declared will have an initial default value whose
byte-representation is all zeros. The “default values” of variables
are the typical “zero-state” of whatever the type is. For example, the
default value for a bool is false. The default value for the uint or
int types is 0. For statically-sized arrays and bytes1 to bytes32,
each individual element will be initialized to the default value
corresponding to its type. Finally, for dynamically-sized arrays,
bytes and string, the default value is an empty array or string.







share|improve this answer


























  • The part to check the non-existence of value to the corresponding key in your mapping is wrong. A value exists, and it is 0. In addition to that, any key mapped to 0 can also be added in an explicit manner.

    – goodvibration
    Dec 26 '18 at 10:18













  • @goodvibration You're right, answer updated.

    – Aniket
    Dec 26 '18 at 10:28











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "642"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fethereum.stackexchange.com%2fquestions%2f64606%2fsolidity-parseerror-with-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You are getting this error because there is nothing like null or undefined in solidity. An uint initializes with 0.



So, to check the zero-state of value(either default or intentionally updated) to the corresponding key in your mapping, you should write it as:



if (itemsPerCreator[_creator] == 0){}


As per the Solidity documentation:




A variable which is declared will have an initial default value whose
byte-representation is all zeros. The “default values” of variables
are the typical “zero-state” of whatever the type is. For example, the
default value for a bool is false. The default value for the uint or
int types is 0. For statically-sized arrays and bytes1 to bytes32,
each individual element will be initialized to the default value
corresponding to its type. Finally, for dynamically-sized arrays,
bytes and string, the default value is an empty array or string.







share|improve this answer


























  • The part to check the non-existence of value to the corresponding key in your mapping is wrong. A value exists, and it is 0. In addition to that, any key mapped to 0 can also be added in an explicit manner.

    – goodvibration
    Dec 26 '18 at 10:18













  • @goodvibration You're right, answer updated.

    – Aniket
    Dec 26 '18 at 10:28
















1














You are getting this error because there is nothing like null or undefined in solidity. An uint initializes with 0.



So, to check the zero-state of value(either default or intentionally updated) to the corresponding key in your mapping, you should write it as:



if (itemsPerCreator[_creator] == 0){}


As per the Solidity documentation:




A variable which is declared will have an initial default value whose
byte-representation is all zeros. The “default values” of variables
are the typical “zero-state” of whatever the type is. For example, the
default value for a bool is false. The default value for the uint or
int types is 0. For statically-sized arrays and bytes1 to bytes32,
each individual element will be initialized to the default value
corresponding to its type. Finally, for dynamically-sized arrays,
bytes and string, the default value is an empty array or string.







share|improve this answer


























  • The part to check the non-existence of value to the corresponding key in your mapping is wrong. A value exists, and it is 0. In addition to that, any key mapped to 0 can also be added in an explicit manner.

    – goodvibration
    Dec 26 '18 at 10:18













  • @goodvibration You're right, answer updated.

    – Aniket
    Dec 26 '18 at 10:28














1












1








1







You are getting this error because there is nothing like null or undefined in solidity. An uint initializes with 0.



So, to check the zero-state of value(either default or intentionally updated) to the corresponding key in your mapping, you should write it as:



if (itemsPerCreator[_creator] == 0){}


As per the Solidity documentation:




A variable which is declared will have an initial default value whose
byte-representation is all zeros. The “default values” of variables
are the typical “zero-state” of whatever the type is. For example, the
default value for a bool is false. The default value for the uint or
int types is 0. For statically-sized arrays and bytes1 to bytes32,
each individual element will be initialized to the default value
corresponding to its type. Finally, for dynamically-sized arrays,
bytes and string, the default value is an empty array or string.







share|improve this answer















You are getting this error because there is nothing like null or undefined in solidity. An uint initializes with 0.



So, to check the zero-state of value(either default or intentionally updated) to the corresponding key in your mapping, you should write it as:



if (itemsPerCreator[_creator] == 0){}


As per the Solidity documentation:




A variable which is declared will have an initial default value whose
byte-representation is all zeros. The “default values” of variables
are the typical “zero-state” of whatever the type is. For example, the
default value for a bool is false. The default value for the uint or
int types is 0. For statically-sized arrays and bytes1 to bytes32,
each individual element will be initialized to the default value
corresponding to its type. Finally, for dynamically-sized arrays,
bytes and string, the default value is an empty array or string.








share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 26 '18 at 10:26

























answered Dec 26 '18 at 10:09









AniketAniket

2,0471633




2,0471633













  • The part to check the non-existence of value to the corresponding key in your mapping is wrong. A value exists, and it is 0. In addition to that, any key mapped to 0 can also be added in an explicit manner.

    – goodvibration
    Dec 26 '18 at 10:18













  • @goodvibration You're right, answer updated.

    – Aniket
    Dec 26 '18 at 10:28



















  • The part to check the non-existence of value to the corresponding key in your mapping is wrong. A value exists, and it is 0. In addition to that, any key mapped to 0 can also be added in an explicit manner.

    – goodvibration
    Dec 26 '18 at 10:18













  • @goodvibration You're right, answer updated.

    – Aniket
    Dec 26 '18 at 10:28

















The part to check the non-existence of value to the corresponding key in your mapping is wrong. A value exists, and it is 0. In addition to that, any key mapped to 0 can also be added in an explicit manner.

– goodvibration
Dec 26 '18 at 10:18







The part to check the non-existence of value to the corresponding key in your mapping is wrong. A value exists, and it is 0. In addition to that, any key mapped to 0 can also be added in an explicit manner.

– goodvibration
Dec 26 '18 at 10:18















@goodvibration You're right, answer updated.

– Aniket
Dec 26 '18 at 10:28





@goodvibration You're right, answer updated.

– Aniket
Dec 26 '18 at 10:28


















draft saved

draft discarded




















































Thanks for contributing an answer to Ethereum Stack Exchange!


  • 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%2fethereum.stackexchange.com%2fquestions%2f64606%2fsolidity-parseerror-with-null%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

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?