谢谢 解决方案 coder写道: 嗨专家, strtod的以下用法是好的(p是一个字符指针): value = strtod(p,& p); 是否有可能引起未定义的行为? 或者我应该使用临时指针然后将其值分配给p? 只要你绕过strtod的任何宏观 定义,你就可以这样做: value =(strtod)(p,& p); 但是暂时使用它会更干净。 2月18日,10:47 pm,Harald van D?3k < true ... @ gmail.comwrote: coder写道: < snip> 感谢回复,Harald。 你可以这样做只要你绕过strtod的任何可能的宏定义: value =(strtod)(p,& p); 我没有得到。你能解释一下吗? 但是使用临时工具会更干净。 coder写道: 嗨专家, strtod的以下用法是否正确(p是一个字符指针): value = strtod(p,& p); 是否有可能引起未定义的行为? 或者我应该使用临时指针然后将其值分配给p? 你应该使用临时的,而不是因为未定义的 行为(但请参阅Harald van D?3k'的回复),但是因为 当你检查 的错误时,你需要原始指针的值。在strtod(p,& q)之后,条件p == q意味着 strtod()无法转换任何输入。如果你用写strtod(p,& p)你将无法进行测试。 - Eric Sosman es*****@acm-dot-org.inva lid Hi experts,Is the following usage of strtod okay (p is a char pointer): value = strtod(p, &p); Is it possible that this would evoke undefined behaviour?Or should I use a temporary pointer and then assign its value to p? Thanks 解决方案 coder wrote:Hi experts,Is the following usage of strtod okay (p is a char pointer):value = strtod(p, &p);Is it possible that this would evoke undefined behaviour?Or should I use a temporary pointer and then assign its value to p?You are allowed to do this as long as you bypass any possible macrodefinition of strtod: value = (strtod) (p, &p); But it would be cleaner to just use a temporary. On Feb 18, 10:47 pm, "Harald van D?3k" <[email protected]:coder wrote: <snip> Thanks for the reply, Harald. You are allowed to do this as long as you bypass any possible macrodefinition of strtod:value = (strtod) (p, &p);I didn''t get that. Can you please explain a little more? But it would be cleaner to just use a temporary. coder wrote:Hi experts,Is the following usage of strtod okay (p is a char pointer):value = strtod(p, &p);Is it possible that this would evoke undefined behaviour?Or should I use a temporary pointer and then assign its value to p?You should use a temporary, not because of undefinedbehavior (but see Harald van D?3k''s response), but becauseyou will need the original pointer''s value when you checkfor errors. After strtod(p, &q), the condition p==q meansstrtod() was unable to convert any of the input. If youwrite strtod(p, &p) you will be unable to make the test. --Eric Sosman es*****@acm-dot-org.invalid 这篇关于使用strtod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 23:41