array declaration without identify array size

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

array declaration without identify array size

1,086 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by murnesty on Sun Mar 24 22:39:30 MST 2013
Yes. Actually... I'm thinking is unsafe too but this is a sample code so I thought there is some trick there.

Thank you. So I just erase his code.
0 项奖励
回复
4 回复数

1,003 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Mar 25 03:57:05 MST 2013

Quote: wrighflyer
I love it when people edit/remove the first post on a forum - ho hum.

Anyway I wonder if malloc() might have been the solution to the problem we'll never see again?



Yes and No :rolleyes:

Following his sample, he is using an 1 char array. So if you also allocate 1 byte, it's the same nonsense :)
0 项奖励
回复

1,003 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wrighflyer on Mon Mar 25 03:36:16 MST 2013
I love it when people edit/remove the first post on a forum - ho hum.

Anyway I wonder if malloc() might have been the solution to the problem we'll never see again?
0 项奖励
回复

1,003 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Mar 25 01:26:04 MST 2013
What do you think is your compiler trying to tell you with:


Quote:

char uart0_buf[];
warning: array 'uart0_buf' assumed to have one element

If you are still unsure about array size, look in your map file:

And surprise, it's 1 byte :) So this is a safe 1 byte array ;)

Then you are filling this array with sprintf:

Quote:

  sprintf(uart0_buf,"Testing1234 - Uart 2\n\r");    // Print Message String

That's safe, too. Sprintf is using start address of array uart0_buf and writing your data ;)

Memory view is showing your string in RAM, so the compiler was executing all your nonsense :D
0 项奖励
回复

1,003 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Mon Mar 25 00:44:45 MST 2013
No it is not safe. Suggest you learn about pointers and arrays.
http://pw1.netcom.com/~tjensen/ptr/pointers.htm
0 项奖励
回复