完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛扫一扫,分享给好友
|
我正在为像ST735这样的所有LCD驱动程序编写一个程序库。库正在工作,一切都还好,但是我有一个函数来设置文本的字体:ValueStCuffType(无符号char字体,unChar char字体,unchar char funw,unchar char间距ECC…)。Edchar * FuntRay.UnSchar Chan-Funw;未签名的Char Fulth.Ec..字体;但XC8不允许我这样做。结构中只有一个指针,不是一个变量或可变大小数组(XC8中不允许)。我只想知道是否有一种方法,如果不是,我只会按原样使用函数。
以上来自于百度翻译 以下为原文 I'm writing a library for all the LCD drivers like st7735. Library is working and all is ok, but i have a function to set the font of text: void setCustomFont(unsigned char *font, unsigned char fontH, unsigned char fontW,unsigned char spacing ecc..) I would like to delcare a typedef struct that contains all of this data like typedef struct font_ { const unsigned char *fontarray; unsigned char fontW; unsigned char fontH; ecc.. }font; But XC8 doesn't let me do this. There is just a pointer in the struct, not a variable or and variable size array(not allowed in xc8). I just want to know if there is a way, if not i will just use the function as is. |
|
相关推荐
17个回答
|
|
|
“不让你”?这意味着什么?如果您正在获取错误,请显示实际代码和实际错误。
以上来自于百度翻译 以下为原文 "Doesn't let you"? What does that mean? If you're getting errors, show the real code and the actual errors. |
|
|
|
|
|
(114)错误:(712)不能为这个表达式生成代码,这是结构:TyBuffFStuts{const unSchar char字体;const unchar char Leeleln;const unchar char ByTelEN;} CustomFont;这是在LabValueToT TftStutoCufFutStutt的头上的声明(CudioToupe)*我在这里定义了Stuttconst无符号char EdWadiaNyByTeleN=4;const un签署char EdWadidiaLieleln=113;const unchar char EdWadidia[] [{0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,…,ec};错误被引用到下一行!!const Cuto字体EdWordNe= { & &;EdWadidiaNi,EdWadiaNo.LeelEnn,EdWadiaNyByTele};在这里,我使用了FuffTftStutufFuconStutt(&;EdWaldiad,1);如果我编译没有最后一行(我调用函数),代码编译得很完美。
以上来自于百度翻译 以下为原文 _font_Edwardian_28_29.h:114: error: (712) can't generate code for this expression this is the struct: typedef struct{ const unsigned char *font; const unsigned char lineLen; const unsigned char byteLen; }CustomFont; This the declaration on the header of the library void TFTSetCustomFontStruct(CustomFont *_font, unsigned char _spacing); This is where i define the struct const unsigned char Edwardian_ByteLen= 4; const unsigned char Edwardian_LineLen = 113; const unsigned char Edwardian_[] = { 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, ....,ecc}; THE ERROR IS REFERRED TO THE NEXT LINE!! const CustomFont Edwardian ={&Edwardian_,Edwardian_LineLen,Edwardian_ByteLen}; And here i use the function TFTSetCustomFontStruct(&Edwardian,1); If i compile without the last line (where i call the function) the code compiles perfectly. |
|
|
|
|
|
如果传递一个指向const的指针,您的函数需要支持:并且不要应用于数组:使用与“x”开头的标识符不是一个好主意,因为它们可能与编译器冲突。
以上来自于百度翻译 以下为原文 If you're passing a pointer to const, your function needs to support that: void TFTSetCustomFontStruct(const CustomFont *_font, unsigned char _spacing); And don't apply & to an array:const CustomFont Edwardian ={Edwardian_,Edwardian_LineLen,Edwardian_ByteLen};And using identifiers that start with "_" is not a good idea since they could conflict with the compiler. |
|
|
|
|
|
不能初始化具有变量的全局结构。你需要明确地使用“4”和“113”,如果你不喜欢数字,你可以这样做:
以上来自于百度翻译 以下为原文 You cannot initialize a global structure with variables. You need to explicitly use "4" and "113" instead. If you don't like numbers, you can do: #define Edwardian_ByteLen 4 #define Edwardian_LineLen 113 |
|
|
|
|
|
我知道不在数组前放置和放置,它只是为了尝试,无论如何,也用声明中的“const”,错误是相同的:错误:(712)不能为这个表达式生成代码。
以上来自于百度翻译 以下为原文 I know not to put & before an array, it was here just for trying, anyway, also with the "const" in the declaration the error is the same : error: (712) can't generate code for this expression |
|
|
|
|
|
你可以做一些类似的事情。在一个TyBufff之后,使用“YT”来避免混淆是一个很好的理想。Gottgt GoRT,* WorkDeavys= & Gort;
以上来自于百度翻译 以下为原文 struct Menu_t{ char **Menu; bool (*timeoutfunc)(); char LeftChar; char RightChar; int MaxLen; int XPos; int YPos; int AnimationTime; int BlinkRate; //0=off int Flag; }Menu={ NULL, alarm_active, CHAR_LARROW, CHAR_RARROW, 0, 8, 2, 5, BLINKRATE, 0}; You can do something like that. After a typedef it is a good ideal to use "_t" to avoid confusion. typedef struct{ int Klattu; int Barada; int Nikto; }Gort_t; Gort_t Gort, *WorldDestroyer=&Gort; |
|
|
|
|
|
|
|
|
|
|
|
你有“FuntTyt”,我看不出来:FuttHut-Poutht需要存在于内存中。
以上来自于百度翻译 以下为原文 You've got "Font_t" I can't see: Font_t font It needs to exist in memory. |
|
|
|
|
|
这不是一个把戏,它告诉菜单FUNC。指针没有指向任何东西,也就是说不使用。
以上来自于百度翻译 以下为原文 It's not a trick, it tells the menu func. that the pointer is not pointing to anything. i.e. do not use. |
|
|
|
|
|
不幸的是,这是一个编译器错误。假设在块范围内,声明没有错。如果您使用EXWADIANYBYTELN和EdWADIAN-LILELN定义对象,而不是对象,则将编译。
以上来自于百度翻译 以下为原文 Unfortunately, that's a compiler bug. There's nothing wrong with that declaration assuming it's at block scope. If you use #defines for Edwardian_ByteLen and Edwardian_LineLen instead of objects, it will compile. |
|
|
|
|
|
不幸的是,这是一个编译器错误。假设在块范围内,声明没有错。如果您使用的是EdWidiaNyByTelEN和EdWADIAN-LILELN定义的对象,它将被编译,这不是编译器错误。不能用其他变量初始化全局变量。你需要一个不变的表达方式。OP使用两个变量——EdWadidiyByeltEn和EdWadiaNo.Leeleln。编译器不能在编译时对它们进行评估。因此出现了误差。我已经在POST第5章中解释过了。
以上来自于百度翻译 以下为原文 Unfortunately, that's a compiler bug. There's nothing wrong with that declaration assuming it's at block scope. If you use #defines for Edwardian_ByteLen and Edwardian_LineLen instead of objects, it will compile. It's not a compiler bug. You cannot initialize global variables with other variables. You need a constant expression. OP used two variables - Edwardian_ByteLen and Edwardian_LineLen. Compiler cannot evaluate them at compile time. Hence the error. I have already explained this in post #5. |
|
|
|
|
|
这就是为什么我说“假设它处于块范围”,在这种情况下,它是完全合法的代码,它仍然生成CGC,这是一个编译器错误。
以上来自于百度翻译 以下为原文 Which is why I said "assuming it's at block scope" in which case it's perfectly legal code -- and it still generates the CGC, which is a compiler bug. |
|
|
|
|
|
我刚刚尝试了定义和编译!但是我不能理解这一点,为什么你说编译器不能知道我的2个变量的大小?变量是用一个不等于表达式的一个变量来定义的,那么,与y定义和一个常数无符号短的区别是什么?编译器应该知道短信息需要2字节。
以上来自于百度翻译 以下为原文 I've just tried with the defines and it compile!! but i can't understend this, why you say that the compiler can't know the size of my 2 variables ? The variables are definited with a costant number not an expression, so what's the difference from the #define and a const unsigned short ? the compiler should know that the short takes 2 bytes. |
|
|
|
|
|
在文件范围内,C是这样工作的。C在初始化时不能“查看”其他变量,即使这些值对读者来说是显而易见的。
以上来自于百度翻译 以下为原文 At file scope, that's how C works. C can't "look into" other variables when initializing, even if it seems that the values are obvious to the reader. |
|
|
|
|
|
“const”不是预处理器将理解为“常量”的东西。
以上来自于百度翻译 以下为原文 A "const" is not something the preprocessor would understand as a "constant" |
|
|
|
|
|
C中的“const”表示只读,而不是从不改变。
以上来自于百度翻译 以下为原文 "const" in C means read-only, not never-changing. |
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475 浏览 0 评论
5795 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1126浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
476浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-3 17:12 , Processed in 3.887833 second(s), Total 107, Slave 89 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1816