What is a macro?

I’m slowly getting to grips with creating a dial plan and have started working with macros and am getting confused. To me, as a programmer used to working in assembly languages, a macro is a piece of code that gets inserted in line each time it is invoked. However, everything about the way my system behaves suggests that, in the Asterisk case, they are actually subroutines. That is, there is only one piece of code that is called each time it is used.

The difference is important because, with a subroutine, you need to make sure you return cleanly from it and don’t jump off to another bit of code. With a macro, you can put whatever you like in there and it will blindly get inserted at compile time.

Are Asterisk macros really subroutines? Do I need to be wary of using statements like Goto and Hangup inside them? Are there any ‘costs’ in using them?

it sounds like it would be moreso a subroutine. The reason is that Asterisk dialplan code never is expected to reach the end and return, the result is (usually) a Dial() command which sends you to somebodys phone or Voicemail() which sends you to VM.

As I understand it, if you call a Macro, and inside the macro is a GoTo which sends you outside of the macro, you are no longer in the macro and execution will continue from where you GoTo’d (not going back to the macro or where it was called from unless you GoTo back there.
Furthermore, if you GoTo out of your macro I don’t think you can GoTo back into the macro because when the macro ends it won’t know where to return to (the place where you originally Macro()'d) and you will fall off the end (call hangs up).

Does that help?