编译器不允许将Char *的维度数组签名到另一个??? [英] compiler won't allow dimensioned array of Char* to be signed to another???
问题描述
我的编译器(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?
推荐答案
Gregg Woodcock写道:
Gregg Woodcock wrote:
我的编译器(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.
Declaration of an array of unknown size will only accept an aggregate
initializer (i.e. ''{}''-enclosed initializer). The one you provided is not.
What am I missing? How can this be done?
你究竟想做什么?
-
祝你好运,
Andrey Tarasevich
What exactly are you trying to do?
--
Best regards,
Andrey Tarasevich
" Gregg Woodcock" < WO ****** @ SonLightSoftware.com>在消息中写道
news:86 ************************** @ posting.google.c om ...
"Gregg Woodcock" <wo******@SonLightSoftware.com> wrote in message
news:86**************************@posting.google.c om...
我的编译器(m68k-gcc)不允许这个(简化示例;不是我的
真实代码),我不明白为什么不:
您可以在此代码中解释您的意图,我会尝试猜测
现在...
{
char * arrayCharPtr1 [ ] = {" a"," ab",NULL};
char * arrayCharPtr2 [] = {" A"," AB",NULL};
你应该在这里使用const char *,因为这些数组持有指向常量
字符串文字的指针。
char * arrayCharPtrVar [] =(/ someBoolean)?arrayCharPtr1:arrayCharPtr2); //< -error在这里!
试试这个:char ** arrayCharPtrVar = someBoolean? arrayCharPtr1:arrayCharPtr2;
如果按照我的建议使用const char ** ...
StrCopy(someString,arrayCharPtr [0]);
StrCopy不是strcpy,它到底能做什么strcpy不能?
}
我也有尝试过=& arrayCharPtr1 [0]我认为应该工作,
;它不是。
问题在于类型本身:你应该声明一个指针,而不是一个
agregate。
我错过了什么?怎么办呢?
My compiler (m68k-gcc) does not allow this (simplified example; not my
real code) and I don''t see why not:
You could have explained what you intended in this code, I will try and guess
for now...
{
char *arrayCharPtr1[] = {"a", "ab", NULL};
char *arrayCharPtr2[] = {"A", "AB", NULL};
You should use const char * here because these arrays hold pointers to constant
string literals.
char *arrayCharPtrVar[] =
((someBoolean) ? arrayCharPtr1 : arrayCharPtr2); // <-error here!
Try this : char **arrayCharPtrVar = someBoolean ? arrayCharPtr1 : arrayCharPtr2;
Use const char **... if you followed my advice above.
StrCopy(someString, arrayCharPtr[0]);
StrCopy is not strcpy, what in hell can it do that strcpy can''t ?
}
I have also tried "= &arrayCharPtr1[0]" which I assumed should work,
too; it doesn''t.
The problem was with the type itself : you should declare a pointer, not an
agregate.
What am I missing? How can this be done?
就像我说的那样。
-
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[]...
Andrey Tarasevich< an ************** @ hotmail.com>在消息新闻中写道:< 10 ************* @ news.supernews.com> ...
Andrey Tarasevich <an**************@hotmail.com> wrote in message news:<10*************@news.supernews.com>...
Gregg Woodcock写道:
Gregg Woodcock wrote:
我的编译器(m68k-gcc)不允许这样(简化示例;不是我的
真实代码),我不明白为什么不:
{char /> 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.
声明一个未知大小的数组只接受一个聚合的初始化器(即''{}'' - 封闭的初始化器)。你提供的那个不是。
Declaration of an array of unknown size will only accept an aggregate
initializer (i.e. ''{}''-enclosed initializer). The one you provided is not.
我错过了什么?怎么办呢?
What am I missing? How can this be done?
你究竟想做什么?
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 *的维度数组签名到另一个???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!