Dear All,

Thank you for your posts. I have tried to pass the address of the first
element of my string to put_message, but that didn't work either. I have got
around my problem, by declaring a global pointer and then inside my function
that has to call put_message, I initialise my global pointer to the address
of the begining of the string.

By doing the above, my program does what I expect.

The original put_message function that I use in my code outputs characters
to a serial port. I didn't post this code onto the newsgroup. I stripped
this function down, to do something basic (incrementing the 1st value of an
array) as you will see in my earlier post and this causes the same problem
to occur, which is why I posted the stripped down code rather that the
output to serial port code.

I'm just using the default compiler flags to compile my code. If they were
changed to something else, would my program be likely to perform
differently?

Thanks again for any help,

Regards,

Alan



bweiss wrote:
> 
> Hi Alan,
> 
> Not quite sure what the function is supposed to actually do given your
> code fragment there.
> GCC works quite well with unsigned char pointers, though gdb might be
> slightly harder to use with them from the command line.
> I can't say I've ever really had to debug string stuff thus far.
> My string print function is simply
> 
> void uart_txs( uint8_t* s)
> {
>     while(*s != '\0')
>         uart_tx(*s++);
> }
> 
> Haven't had any problems with it at all.
> I regularly call it as uart_txs("Hello\r\n");
> 
> 
> If you actually have in your put_message function the whole
> msg[0]++;
> thing then it might cause issues.  String literals are constants and
> shouldn't be modified unless you really know what you're doing, and where
> the string literal has been placed.
> 
> Regards,
> Bevan
> 
> 
>> Date: Thu, 16 Aug 2007 03:03:08 -0700
>> From: [email protected]
>> To: [email protected]
>> Subject: [Mspgcc-users] passing a pointer to a function with MSP430 gcc
>> 
>> 
>> Dear All,
>>  
>> I'm trying to recompile some c code that was initially with IAR in gcc.
>> My
>> function that doesn't work, is supposed to write characters to a serial
>> port. 
>> 
>> The prototype of my function to write to a serial port, is:
>> void put_message( unsigned char *s);
>> 
>> I then call this function like so:
>> put_message( "TEST");
>> 
>> If I put a breakpoint inside the put_message function and  examine the
>> value
>> of *s, I get 0. I've examined the "memory map" around s in gcc, and the
>> memory locations after s are also set to 0.
>> 
>> Does gcc not like unsigned char pointers? 
>>  
>> Here's a small snippet of code where the problem occurs:
>>  
>> #include <msp430x42x.h>
>> 
>>  
>> 
>> 
>> void put_message(unsigned char *msg){
>> 
>>     msg[0]++;
>> 
>>    msg[0]++;
>> 
>>     msg[0]++;
>> 
>>     msg[0]++;
>> 
>> }
>> 
>>  
>> 
>> 
>> int main(void){
>> 
>>     int i = 0;
>> 
>> 
>>     unsigned char message[10];
>> 
>>  
>> 
>> 
>>     message[0]=1;
>> 
>>     message[1]=2;
>> 
>>     message[2]=3;
>> 
>>     message[3]=4;
>> 
>> 
>>     P1SEL = 0;
>> 
>>     P1DIR = P1DIR | 0x8;
>> 
>>     while (1){
>> 
>>         P1OUT = P1OUT | 0x8;
>> 
>>         for (i=0;i<1000;i++){}
>> 
>>         P1OUT = P1OUT & 0xf7;
>> 
>>         for (i=0;i<1000;i++){}
>> 
>> 
>>         put_message(message); //neither of these function calls produce
>> the
>> correct value in put_message
>> 
>>         put_message("test");
>> 
>> 
>>     }
>> 
>> }
>> 
>> Do you have any suggestions? Thanks in advance for your help,
>>  
>> Regards,
>>  
>> Alan
>> -- 
>> View this message in context:
>> http://www.nabble.com/passing-a-pointer-to-a-function-with-MSP430-gcc-tf4278688.html#a12178517
>> Sent from the MSP430 gcc - Users mailing list archive at Nabble.com.
>> 
>> 
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Splunk Inc.
>> Still grepping through log files to find problems?  Stop.
>> Now Search log events and configuration files using AJAX and a browser.
>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>> _______________________________________________
>> Mspgcc-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
> 
> _________________________________________________________________
> News, entertainment and everything you care about at Live.com. Get it now!
> http://www.live.com/getstarted.aspx
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Mspgcc-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/passing-a-pointer-to-a-function-with-MSP430-gcc-tf4278688.html#a12239423
Sent from the MSP430 gcc - Users mailing list archive at Nabble.com.


Reply via email to