本文介绍了编译器不允许将Char *的维度数组签名到另一个???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的编译器(m68k-gcc)不允许这样(简化示例;不是我的

真实代码),我不明白为什么不:

{

char * arrayCharPtr1 [] = {" a"," ab",NULL};

char * arrayCharPtr2 [] = {" A"," AB",NULL};

char * arrayCharPtrVar [] =

((someBoolean)?arrayCharPtr1:arrayCharPtr2); //< -error here!

StrCopy(someString,arrayCharPtr [0]);

}


我也有尝试过=& arrayCharPtr1 [0]我认为应该工作,

;它没有。


我缺少什么?如何做到这一点?

My compiler (m68k-gcc) does not allow this (simplified example; not my
real code) and I don''t see why not:
{
char *arrayCharPtr1[] = {"a", "ab", NULL};
char *arrayCharPtr2[] = {"A", "AB", NULL};
char *arrayCharPtrVar[] =
((someBoolean) ? arrayCharPtr1 : arrayCharPtr2); // <-error here!
StrCopy(someString, arrayCharPtr[0]);
}

I have also tried "= &arrayCharPtr1[0]" which I assumed should work,
too; it doesn''t.

What am I missing? How can this be done?

推荐答案




你究竟想做什么?


-

祝你好运,

Andrey Tarasevich



What exactly are you trying to do?

--
Best regards,
Andrey Tarasevich





就像我说的那样。


-

Chqrlie。

PS:你的命名约定也是幼稚的。 CharPtr没用,Var是变量名无意义的。
使用像lower_strings []和upper_strings []这样的名字......



Like I say.

--
Chqrlie.
PS: also your naming conventions are childish. CharPtr is useless, Var is
meaningless in variable names.
Use names like lower_strings[] and upper_strings[]...




声明一个未知大小的数组只接受一个聚合的初始化器(即''{}'' - 封闭的初始化器)。你提供的那个不是。



Declaration of an array of unknown size will only accept an aggregate
initializer (i.e. ''{}''-enclosed initializer). The one you provided is not.



你究竟想做什么?



What exactly are you trying to do?




你做了一个相当不错的编译器模仿:非常准确,而且
完全没用。

我*知道*我不能做我想做的事情我想做的事

(编译器非常清楚);这就是为什么我给出了

完整的上下文,显示了我想做的事情。我几乎不能更多

清楚。


我必须使用字符串数组。

我想分配一个或另一个数组到一个变量,这样我就可以用数组var [index]来索引数组中的任何字符串。

这很简单,我肯定不是不可能的。 ..



You do a pretty good compiler immitation: perfectly accurate and
totally worthless.
I *KNOW* I cannot do what I want to do the way I am trying to do it
(the compiler is quite clear about that); That''s why I gave the
complete context showing WHAT I want to do. I can hardly be more
clear.

I have to arrays of strings.
I want to assign one or the other array to a variable such that I can
index any string in the array with something like var[index].
It is very simple and I am quite sure not impossible...


这篇关于编译器不允许将Char *的维度数组签名到另一个???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 23:39