getopt - command line options parsing

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

getopt - command line options parsing

718 次查看
jd-soc
Contributor II

Hi all,


I'm trying to use getopt (from <unistd.h>) in some LPC-projects, where I have a small shell running.
Part of this shell is doing the command line processing, where I then need to process different kind of options.
I would like this to be as generic as possible, hence getopt().

The problem I'm facing at the moment is when playing around with heap/stack, I often get a HardFault.
This is because I don't know the memory usage/needs of getopt().

Is there a way to estimate its max usage, without having access to the implementation?

I know using such function on an embedded target might be discouraged, but re-inventing the wheel each time is also not really convenient, nor maintainable.

(Or has someone an alternative or better ideas ?)

My configuration:
LPCOpen C++ project with NewLib
MCUXpresso
LPC1769

Thanks for your help!

标签 (3)
0 项奖励
2 回复数

552 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi Julien Delbergue,

Thank you for your interest in NXP Semiconductor products and 
for the opportunity to serve you.
Optimizing the heap and stack may be a good way, and in the MCUXpresso IDE user's guide, 11.9 More advanced heap/stack placement illustrates the detailed information.
Hope this helps.

Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励

552 次查看
jd-soc
Contributor II

Hi jeremyzhou,
Thanks for your answer.

I don't think it actually is because of memory layout (12.9 btw in the latest user's guide).
I suspect it is because I'm using C++, and most likely this getopt implementation is using malloc, which is discouraged in C++ from what I am reading.

Could you maybe confirm that malloc is being used in your getopt implementation ?
I'm still open to alternatives or other ideas.

Cheers,

Julien

0 项奖励