如果没有看到任何代码,那就是我可以管理的所有 猜测。 - Er ********* @ sun.com 你的指针算术没有任何本质上的错误,如果这就是让你担心的事情。但是请注意,这并不是神奇地创造了100个额外的字节。你实际上在做的是分享后两半的200-char缓冲区,使用那些位置来输入和长输出的尾端。在您处理之前,您的输出字符是否在您的输入中踩到了?你是说,把数据读入 inputBuffer,然后用空白填充outputBuffer,然后尝试处理突然全空的inputBuffer? 没见过任何代码,都是关于我能管理的所有猜测。 There''s nothing inherently wrong with your pointerarithmetic, if that''s what''s worrying you. Note, though,that this doesn''t magically create 100 extra bytes outof thin air. What you''re actually doing is sharing thelatter half of the 200-char buffer, using those locationsfor input and for the tail end of long outputs. Are youroutput characters stomping all over your inputs beforeyou''ve processed them? Are you, say, reading data intoinputBuffer, then filling outputBuffer with blanks, thentrying to process the suddenly all-blank inputBuffer? Without having seen any code, that''s about all theguessing I can manage. 该死的,我确实遗漏了一段。 所以是的,我没有神奇地创造100字节,我只是在特殊情况下分享那个 回100(如果我确定输入缓冲区中的信息,我不会介意)。正常情况不应该是b $ b b是一个问题 我遇到的问题是,我的函数似乎与一起工作: unsigned char inputBuffer [100]; unsigned char outputBuffer [100]; don''似乎正在使用: unsigned char inputBuffer [100]; unsigned char * inputBuffer = outputBuffer + 100; 这些函数不会产生足够的数据来实际敲击 100字节的限制。 例如: 无效SPI_receive() { systat_7 = 0; SPICON = 0x31; SPI_COMM_SS = 0; SPIDAT = 0; 而(ISPI == 0); inputBuffer [spi_in] = SPIDAT ; ++ spi_in; if(!( - spiSize)){ systat_3 = 1; systat_1 = 0; } SPI_COMM_SS = 1; } void spi_getSize( ) { *((char *)& spiSize)= inputBuffer [1]; *((char *)& spiSize + 1)= inputBuffer [2]; } 无效SPI_send() { systat_7 = 0; SPICON = 0x31; if(!systat_5){ SPI_COMM_SS = 0; SPIDAT = outputBuffer [OB_out]; while(ISPI == 0); if(!( - spiSize)) systat_5 = 1; + + OB_out; ISPI = 0; SPI_COMM_SS = 1; } else { systat_1 = systat_3 = systat_5 = systat_6 = 0; systat_4 = 1; } } 这些似乎是我现在的问题函数。发生的事情是 ,你最初通过SPI总线读取3个字节的数据。那么你 调用spi_getSize(),这样就知道发送了多少个字符。 然后你开始使用SPI_receive()从公共汽车上拉出数据1 /> 一次一个字符并将其放入缓冲区。完成一些 处理后,通过SPI_send将响应发送回 SPI总线。 spi_in和OB_out只是索引,允许我通过缓冲区逐个字符遍历。每个缓冲区都有一个out和 的指示(spi_in / spi_out和OB_in / OB_out) RonBDamn, I did leave out a paragraph on this.So yea, I didn''t magically create 100 bytes, I am just sharing thatback 100 under the special circumstances (which I won''t mind if Iclobber the information in the input Buffer). Normal cases should notbe a problemWhat problem that I am having is that it seems my functions whichworked with:unsigned char inputBuffer[100];unsigned char outputBuffer[100];don''t appear to be working with:unsigned char inputBuffer[100];unsigned char *inputBuffer = outputBuffer + 100;These are functions which don''t produce enough data to actually hitthe 100 byte limit.For example:void SPI_receive(){systat_7 = 0;SPICON = 0x31;SPI_COMM_SS = 0;SPIDAT = 0;while (ISPI == 0);inputBuffer[spi_in] = SPIDAT;++spi_in;if(!(--spiSize)){systat_3 = 1;systat_1 = 0;}SPI_COMM_SS = 1;}void spi_getSize(){*((char*)&spiSize ) = inputBuffer[1];*((char*)&spiSize+1) = inputBuffer[2];}void SPI_send(){systat_7 = 0;SPICON = 0x31;if(!systat_5){SPI_COMM_SS = 0;SPIDAT = outputBuffer[OB_out];while (ISPI == 0);if(!(--spiSize))systat_5 = 1;++OB_out;ISPI = 0;SPI_COMM_SS = 1;}else{systat_1 = systat_3 = systat_5 = systat_6 = 0;systat_4 = 1;}}These appear to be my problem functions right now. What happens isthat you xfer 3 bytes of data over the SPI bus initially. Then youcall spi_getSize(), so you know how many characters are being sent.Then you start to use SPI_receive() to pull data off the bus 1character at a time and place it into the buffer. After someprocessing is done, and then the response is sent back out across theSPI bus via SPI_send.spi_in and OB_out are just indices which allow me to traversecharacter by character through the buffers. There is an out and inindice for each buffer (spi_in/spi_out and OB_in/OB_out)RonB 你的指针算术本身并没有什么问题,如果这就是令你担心的事情。但是请注意,这并不是神奇地创造了100个额外的字节。你实际上在做的是分享后两半的200-char缓冲区,使用那些位置来输入和长输出的尾端。在您处理之前,您的输出字符是否在您的输入中踩到了?比方说,你是把数据读入 inputBuffer,然后用空白填充outputBuffer,然后尝试处理突然全空的inputBuffer? 没有看到任何代码,那个关于我可以管理的所有猜测。 There''s nothing inherently wrong with your pointerarithmetic, if that''s what''s worrying you. Note, though,that this doesn''t magically create 100 extra bytes outof thin air. What you''re actually doing is sharing thelatter half of the 200-char buffer, using those locationsfor input and for the tail end of long outputs. Are youroutput characters stomping all over your inputs beforeyou''ve processed them? Are you, say, reading data intoinputBuffer, then filling outputBuffer with blanks, thentrying to process the suddenly all-blank inputBuffer? Without having seen any code, that''s about all theguessing I can manage. 该死的,我确实遗漏了一个段落。 所以是的,我没有神奇地创造100个字节,我只是分享那个 我遇到的问题是,我的功能似乎与一起工作: unsigned char inputBuffer [100]; unsigned char outputBuffer [100]; 似乎没有使用: Damn, I did leave out a paragraph on this.So yea, I didn''t magically create 100 bytes, I am just sharing thatback 100 under the special circumstances (which I won''t mind if Iclobber the information in the input Buffer). Normal cases should notbe a problemWhat problem that I am having is that it seems my functions whichworked with:unsigned char inputBuffer[100];unsigned char outputBuffer[100];don''t appear to be working with: ONE THING !! 我不知道这是否有所作为,但是...... 我忘了提及,inputBuffer和outputBuffer都是全局的。 它们是通过SPI例程中的extern访问的。这个 会有什么不同吗?ONE THING!!I don''t know if this makes a difference or not, BUT...I forgot to mention, inputBuffer and outputBuffer are both global.They are being accessed via extern in the SPI routines. Will thismake any sort of differnce? 这篇关于多个数组和指针问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!