[推测字节是typedefed。] 你必须进行明确的演员: func((字节const(*)[16])& bar2); 当然,这会丢失类型检查,但仅限于 你施放它的情况。 - 理查德 - "考虑应该在一些字母表中需要多达32个字符 - X3.4,1963。 可能用C编译器进行编译就足够了。看起来 就像你在使用C ++一样。 其实我不是。谢谢你的猜测。什么C编译器 您使用它编译此代码而不发出诊断? typedef unsigned char byte; void func (byte const(* data)[16]){} int main() { byte bar [16] = {0 }; func(& bar); } I have a function that always takes 16 bytes of data and doesn''t modifyit:void func( byte const (*data)[16] );However, if I try to call it with non-const data, the compiler isunable to perform the conversion:static const byte bar1[16] = { 0 };int foo(){byte bar2[16] = { 0 };func( &bar1 ); /* OK */func( &bar2 ); /* Error */}Is there any work-around to this, other than defining a const and anonconst version of func, or passing a pointer to the first elementof data and thereby losing the compile-time length check? 解决方案Probably it will be enough to compile with a C compiler. Lookslike you are using C++.--Chuck F (cbfalconer at maineline dot net)Available for consulting/temporary embedded and systems.<http://cbfalconer.home.att.net>[Presumably byte is typedefed.]You''ll have to put in an explicit cast:func( (byte const (*)[16]) &bar2 );Of course, this loses the type checking, but only for the cases whereyou cast it.-- Richard--"Consideration shall be given to the need for as many as 32 charactersin some alphabets" - X3.4, 1963.Probably it will be enough to compile with a C compiler. Lookslike you are using C++.Actually I''m not. Thanks for guessing though. What C compiler areyou using that compiles this code without issuing a diagnostic?typedef unsigned char byte;void func( byte const (*data)[16] ) {}int main(){byte bar[16] = { 0 };func( &bar );} 这篇关于恼人的常见问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 18:55