> I'm a little confused here - C does not normally support nested > functions, does it? Is this part of the C99 standard? If so, then it's > great that
C does not normally support nested functions, this is a gcc extension. > msp430-gcc supports them. However, are they actually any real use? I > have Yes, very convenient mechanism for local reaction on an interrupt - you do not have to allocate global vars and such. Any cleanup can be done on the local stack. > done many years programming in Pascal, a language that does support > nested functions, and I have not found any need for nested functions - > indeed, I have found them to be confusing and difficult to maintain, as > well as being less efficient in use (in Pascal, anyway). Obviously they > don't do any harm - if I don't want to use them, I don't have to. But > I'm just trying to see if there are circumstances where code can really > be written better by using them. I suppose if you have optomisation > turned on, then the compiler will probably in-line nested functions > where possible, so if you like that style of coding, it will give you > quite a powerful mechanism for splitting a function into seperate parts > without any overhead (other than compiler effort!). > > Why does the code get enlarged by 48 bytes? Only if you export your local nested function outside the parents scope, the code will be enlarged - 8 bytes on local stack is allocated for function call (in order to call nested function from outside) . 48 bytes are - 8 bytes trampoline template, 8 bytes on stack and 24 bytes of code, which copies context and funct address to stack. If you're using nested call within a parent's scope, this does not involve any overhead (but only 1 insn/cycle - mov r1,r6 or mov r4,r6 before funct call). If you declare it as inline - this will be (hopefully) inlined. > > > > > Anyway, this is a supported feature, which msp430-gcc has (avr does > > not ;) > > > > 4. attribute 'reentrant' added. (Not in includes) > > > > This attribute forces gcc to issue eint/dint on function entry/exit > > irrespective to the status register state. > > > > Is there any nice way to add an eint/dint to a function that *is* > dependant on the status register state? I very often need to be able to > turn off interrupts, then restore them to the previous state - it is > extremly useful for accessing hardware or data structures from either > interrupt routines or background routines. > Within ISR interrups are disabled unless you reenable it (with enablenested attribute). For non-IRS: Yes, there is an attribute 'critical' (read doc.txt) which does as follows: funct: push r2 ; save status dint ; disable ints ...pushes .... funct body follows ...pops reti ; restore r2 and return. So, type critical funct(argtype arg) { type var; ... return var; } will be reentrant under any circumstances. cheers, ~d > mvh. > > David > > > > > > > > Have fun > > ~d > > > > > > > ------------------------------------------------------- > In remembrance > www.osdn.com/911/ > _______________________________________________ > Mspgcc-users mailing list > Mspgcc-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/mspgcc-users > > /******************************************************************** ("`-''-/").___..--''"`-._ (\ Dimmy the Wild UA1ACZ `6_ 6 ) `-. ( ).`-.__.`) Enterprise Information Sys (_Y_.)' ._ ) `._ `. ``-..-' Nevsky prospekt, 20 / 44 _..`--'_..-_/ /--'_.' ,' Saint Petersburg, Russia (il),-'' (li),' ((!.-' +7 (812) 3468202, 5585314 ********************************************************************/