getopt - command line options parsing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

getopt - command line options parsing

693 Views
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!

Labels (3)
0 Kudos
2 Replies

527 Views
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 Kudos

527 Views
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 Kudos