Thread: non maskable global/local variables

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    68

    non maskable global/local variables

    Hello Everyone

    Please bear with me if this sounds a bit silly.
    I would like to know if there is a way(piece of code/snippet in C) by which
    at any time during a program execution by pressing a specific key i can jump to a specific location/line in the program.

    It is like the non-maskable highest priority interrupt concept(all you embedded guys may know this),where in at any given time if a non-maskable interrupt occurs,the micro-controller leaves/abandons what ever its doing and first does what ever is writen in the ISR(interrupt service routine) and then goes back to pick up where it left of.

    I can provide an example if i am not clear to you guys.

    Thanks in advance
    Arun
    Last edited by ak47; 05-26-2014 at 04:16 AM.

  2. #2
    Registered User
    Join Date
    May 2014
    Posts
    121
    You can set up a signal handler that catches SIGINT and then trigger SIGINT with the keyboard to jump to the signal handler whenever you want (it's usually CTRL + C). You can also use the program stty to change which keys that trigger SIGINT. There are a few other signals you can use as well. You can theoretically jump out of the signal handler with setjmp/longjmp but I don't recommend it unless you really know what you're doing.

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I would like to know if there is a way(piece of code/snippet in C) by which at any time during a program execution by pressing a specific key i can jump to a specific location/line in the program.
    O_o

    That is an extremely bad idea.

    Even if you use everything correctly, such as handling all the signals properly without violating the "async" rule, you may wind up with a broken stack depending on the users environment.

    I find it unlikely you event want to do such a thing. If you jump out of the signal handler, execution will not naturally return to the code at the point "interrupted".

    If you only want to execute arbitrary code, as opposed to "safe for signal handlers", you should pretty much do this through an event system. Register that a signal was triggered, somehow, so that you may process the fact that you received a signal however you like.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do the global and local variables use the RAM?
    By YuminZhao in forum C++ Programming
    Replies: 2
    Last Post: 09-04-2011, 10:45 AM
  2. Local vs Global Variables
    By BENCHMARKMAN in forum C++ Programming
    Replies: 5
    Last Post: 07-03-2007, 05:17 AM
  3. local and global variables???
    By geo_c in forum C Programming
    Replies: 5
    Last Post: 08-23-2004, 03:02 PM
  4. Global Vs Local Variables
    By Waldo2k2 in forum C++ Programming
    Replies: 17
    Last Post: 11-11-2002, 07:51 PM
  5. global and local variables
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2001, 01:17 PM