LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1373|回复: 11

zhcon 里面这个函数为什么编译时会出错?(gcc-4.0)

[复制链接]
发表于 2005-4-25 13:53:44 | 显示全部楼层 |阅读模式
  1. void FBLinear24::DrawChar(int x,int y,int fg,int bg,struct CharBitMap* pFont) {
  2.     __u32 eorx, fgx, bgx, d1, d2, d3, d4;
  3.     fgx = cfb24[fg];
  4.     bgx = cfb24[bg];
  5.     eorx = fgx ^ bgx;

  6.     __u8* dest = ((__u8*)mpBuf + mNextLine * y + x * 3 );
  7.     __u32* dest32;

  8.     char* cdat = pFont->pBuf;
  9.     int cnt;
  10.     int row;
  11.     for (row = mBlockHeight; row-- ; dest += mNextLine) {
  12.         dest32 = (__u32*)dest;
  13.         for (cnt = (pFont->w)/8; cnt--;) {
  14.             d1 = (-(*cdat >> 7) & eorx) ^ bgx;
  15.             d2 = (-(*cdat >> 6 & 1) & eorx) ^ bgx;
  16.             d3 = (-(*cdat >> 5 & 1) & eorx) ^ bgx;
  17.             d4 = (-(*cdat >> 4 & 1) & eorx) ^ bgx;
  18.             store4pixels(d1, d2, d3, d4, dest32);
  19.             dest32 += 3;

  20.             d1 = (-(*cdat >> 3 & 1) & eorx) ^ bgx;
  21.             d2 = (-(*cdat >> 2 & 1) & eorx) ^ bgx;
  22.             d3 = (-(*cdat >> 1 & 1) & eorx) ^ bgx;
  23.             d4 = (-(*cdat & 1) & eorx) ^ bgx;
  24.             store4pixels(d1, d2, d3, d4, dest32);
  25.             dest32 += 3;
  26.             cdat++;
  27.         }
  28.         if (pFont->isMulti8)
  29.             continue;
  30.             
  31.         if (pFont->w & 4) {
  32.             d1 = (-(*cdat >> 7) & eorx) ^ bgx;
  33.             d2 = (-(*cdat >> 6 & 1) & eorx) ^ bgx;
  34.             d3 = (-(*cdat >> 5 & 1) & eorx) ^ bgx;
  35.             d4 = (-(*cdat >> 4 & 1) & eorx) ^ bgx;
  36.             store4pixels(d1, d2, d3, d4, dest32);
  37.             dest32 += 3;
  38.         }
  39.         if (pFont->w & 2) {
  40.             d1 = (-(*cdat >> 3 & 1) & eorx) ^ bgx;
  41.             d2 = (-(*cdat >> 2 & 1) & eorx) ^ bgx;
  42.             fb_writel(d1 | (d2<<24), dest32++);
  43.             fb_writew(d2>>8, ((__u16*)dest32)++);
  44.         }
  45.         if (pFont->w & 1) {
  46.             d3 = (-(*cdat >> 1 & 1) & eorx) ^ bgx;
  47. [color=red]            fb_writew(d3, ((__u16*)dest32)++);[/color]
  48.             fb_writeb(d3>>16, (__u8*)dest32);
  49.         }
  50.         cdat++;
  51.     }
  52. }

复制代码


fb_writew(d3, ((__u16*)dest32)++);
这一句的意思是什么?dest32 的指针究竟移动了没有, 移动了多少? fb_writew 接受到的参数又是什么?这种情况下解释的顺序是什么, 在 linux 和 freeBSD 中有没有不同? 在 debian 的 patch 中简单地做了 dest32++, 究竟对不对?
//bow
 楼主| 发表于 2005-4-25 13:54:28 | 显示全部楼层

zhcon 里面这个函数为什么编译时会出错?(gcc-4.0)

  1. void FBLinear24::DrawChar(int x,int y,int fg,int bg,struct CharBitMap* pFont) {
  2.     __u32 eorx, fgx, bgx, d1, d2, d3, d4;
  3.     fgx = cfb24[fg];
  4.     bgx = cfb24[bg];
  5.     eorx = fgx ^ bgx;

  6.     __u8* dest = ((__u8*)mpBuf + mNextLine * y + x * 3 );
  7.     __u32* dest32;

  8.     char* cdat = pFont->pBuf;
  9.     int cnt;
  10.     int row;
  11.     for (row = mBlockHeight; row-- ; dest += mNextLine) {
  12.         dest32 = (__u32*)dest;
  13.         for (cnt = (pFont->w)/8; cnt--;) {
  14.             d1 = (-(*cdat >> 7) & eorx) ^ bgx;
  15.             d2 = (-(*cdat >> 6 & 1) & eorx) ^ bgx;
  16.             d3 = (-(*cdat >> 5 & 1) & eorx) ^ bgx;
  17.             d4 = (-(*cdat >> 4 & 1) & eorx) ^ bgx;
  18.             store4pixels(d1, d2, d3, d4, dest32);
  19.             dest32 += 3;

  20.             d1 = (-(*cdat >> 3 & 1) & eorx) ^ bgx;
  21.             d2 = (-(*cdat >> 2 & 1) & eorx) ^ bgx;
  22.             d3 = (-(*cdat >> 1 & 1) & eorx) ^ bgx;
  23.             d4 = (-(*cdat & 1) & eorx) ^ bgx;
  24.             store4pixels(d1, d2, d3, d4, dest32);
  25.             dest32 += 3;
  26.             cdat++;
  27.         }
  28.         if (pFont->isMulti8)
  29.             continue;
  30.             
  31.         if (pFont->w & 4) {
  32.             d1 = (-(*cdat >> 7) & eorx) ^ bgx;
  33.             d2 = (-(*cdat >> 6 & 1) & eorx) ^ bgx;
  34.             d3 = (-(*cdat >> 5 & 1) & eorx) ^ bgx;
  35.             d4 = (-(*cdat >> 4 & 1) & eorx) ^ bgx;
  36.             store4pixels(d1, d2, d3, d4, dest32);
  37.             dest32 += 3;
  38.         }
  39.         if (pFont->w & 2) {
  40.             d1 = (-(*cdat >> 3 & 1) & eorx) ^ bgx;
  41.             d2 = (-(*cdat >> 2 & 1) & eorx) ^ bgx;
  42.             fb_writel(d1 | (d2<<24), dest32++);
  43.             fb_writew(d2>>8, ((__u16*)dest32)++);
  44.         }
  45.         if (pFont->w & 1) {
  46.             d3 = (-(*cdat >> 1 & 1) & eorx) ^ bgx;
  47. [color=red]            fb_writew(d3, ((__u16*)dest32)++);[/color]
  48.             fb_writeb(d3>>16, (__u8*)dest32);
  49.         }
  50.         cdat++;
  51.     }
  52. }

复制代码


fb_writew(d3, ((__u16*)dest32)++);
这一句的意思是什么?dest32 的指针究竟移动了没有, 移动了多少? fb_writew 接受到的参数又是什么?这种情况下解释的顺序是什么, 在 linux 和 freeBSD 中有没有不同? 在 debian 的 patch 中简单地做了 dest32++, 究竟对不对?
//bow
回复 支持 反对

使用道具 举报

发表于 2005-4-25 14:23:40 | 显示全部楼层
作了个实验:

printf("sizeof(long)=%d,sizof(short)=%d\n",sizeof(long),sizeof(short));
long * l = (long*)malloc(sizeof(long));
printf("%x\n",l);
short* s = ((short*)l)++;
printf("%x,%x\n",l,s);

实验结果:
sizeof(long)=4,sizof(short)=2
823f008
823f00a,823f008
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-25 14:59:16 | 显示全部楼层
[root@geeks int32]# gcc test2.c
test2.c: In function ‘main’:
test2.c:4: warning: incompatible implicit declaration of built-in function ‘printf’
test2.c:5: warning: incompatible implicit declaration of built-in function ‘malloc’
test2.c:7: error: invalid lvalue in increment

我担心的是在不同的平台中解释是不一样的, 所以才再问问。为什么我编译不过去呢?
回复 支持 反对

使用道具 举报

发表于 2005-4-25 16:44:08 | 显示全部楼层
楼上的明显头文件不对啊,加上#include <string.h>
#include <stdio.h>
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-25 17:46:56 | 显示全部楼层

继续问,这次是 cce-0.51/include/defs.h 编译出错

  1. static inline void bzero2(void *head, int n)
  2. {
  3.         while (n-- > 0)
  4.                 *((unsigned char *)head)++ = (unsigned char)0x0;
  5. }

  6. static inline void wzero(void *head, int n)
  7. {
  8.         n >>= 1;
  9.         while (n-- > 0)
  10.                 *((unsigned short *)head)++ = (unsigned short)0x0;

  11. }

  12. static inline void lzero(void *head, int n)
  13. {
  14.         n >>= 2;
  15.     while (n-- > 0)
  16.         *((unsigned int *)head)++ = (unsigned int)0x0;
  17. }

  18. static inline void bmove(void *dst, void *src, int n)
  19. {
  20.         while(n-- > 0)
  21.                 *((unsigned char *)dst)++ = *((unsigned char *)src)++;
  22. }

  23. static inline void brmove(void *dst, void *src, int n)
  24. {
  25.     while(n-- > 0)
  26.         *--((unsigned char *)dst) = *--((unsigned char *)src);
  27. }

  28. static inline void wmove(void *dst, void *src, int n)
  29. {
  30.         n >>= 1;
  31.     while(n-- > 0)
  32.         *((unsigned short *)dst)++ = *((unsigned short *)src)++;
  33. }

  34. static inline void lmove(void *dst, void *src, int n)
  35. {
  36.         n >>= 2;
  37.         while(n-- > 0)
  38.                 *((unsigned int *)dst)++ = *((unsigned int *)src)++;
  39. }
复制代码


问题是一样的
../../include/defs.h: In function ‘bzero2’:
../../include/defs.h:61: error: invalid lvalue in increment
../../include/defs.h: In function ‘wzero’:
../../include/defs.h:68: error: invalid lvalue in increment
../../include/defs.h: In function ‘lzero’:
../../include/defs.h:76: error: invalid lvalue in increment
../../include/defs.h: In function ‘bmove’:
../../include/defs.h:82: error: invalid lvalue in increment
../../include/defs.h:82: error: invalid lvalue in increment
../../include/defs.h: In function ‘brmove’:
../../include/defs.h:88: error: invalid lvalue in decrement
../../include/defs.h:88: error: invalid lvalue in decrement
../../include/defs.h: In function ‘wmove’:
../../include/defs.h:95: error: invalid lvalue in increment
../../include/defs.h:95: error: invalid lvalue in increment
../../include/defs.h: In function ‘lmove’:
../../include/defs.h:102: error: invalid lvalue in increment
../../include/defs.h:102: error: invalid lvalue in increment

不知道应该怎么改合适, n 看上去像是字节, 那么为什么要用几个不同的函数做同一件事呢?如果 n 是个奇数,不是会少做一次赋值吗?另外,
  1. [color=red]        *--((unsigned char *)dst) = *--((unsigned char *)src);[/color]
复制代码
这里的执行顺序是什么? *src 有没有被复制呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-25 17:48:44 | 显示全部楼层
while(n-->0) 是不是说一共执行了 n+1 次, 所以在出现奇数 n 的时候一定会多复制一个或三个字节呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-4-25 18:06:11 | 显示全部楼层
把那些函数都换成 memset 和 memmove 行不行啊
那个 brmove 怎么重写比较好呢?
  1. static inline void brmove(void *dst, void *src, int n)
  2. {
  3.     while(n-- > 0)
  4.         *--((unsigned char *)dst) = *--((unsigned char *)src);
  5. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2005-4-25 18:13:51 | 显示全部楼层
用gcc34能编译么?

你看看Mandriva的srpm能编译不?
http://ftp.sunet.se/pub/os/Linux ... -0.2.3-7mdk.src.rpm
回复 支持 反对

使用道具 举报

发表于 2005-4-25 18:25:25 | 显示全部楼层
这里是mandriva的有关patch:
  1.              d1 = (-(*cdat >> 3 & 1) & eorx) ^ bgx;
  2.              d2 = (-(*cdat >> 2 & 1) & eorx) ^ bgx;
  3.              fb_writel(d1 | (d2<<24), dest32++);
  4. -            fb_writew(d2>>8, ((__u16*)dest32)++);
  5. +            __u16* dest16 = (__u16*)dest32;
  6. +            fb_writew(d2>>8, (dest16)++);
  7.          }
  8.          if (pFont->w & 1) {
  9.              d3 = (-(*cdat >> 1 & 1) & eorx) ^ bgx;
  10. -            fb_writew(d3, ((__u16*)dest32)++);
  11. +            __u16* dest16 = (__u16*)dest32;
  12. +            fb_writew(d3, (dest16)++);
  13.              fb_writeb(d3>>16, (__u8*)dest32);
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表