What is the difference between macros and functions in Rust? -


quoted rust blog:

one last thing mention: rust’s macros different c macros, if you’ve used those

what difference between macros , function in rust? how different c?

keep on reading documentation, the chapter on macros!

the biggest difference, me, macros hygenic. book has example explains hygiene prevents, , says:

each macro expansion happens in distinct ‘syntax context’, , each variable tagged syntax context introduced.

it uses example:

for example, c program prints 13 instead of expected 25.

#define five_times(x) 5 * x  int main() {     printf("%d\n", five_times(2 + 3));     return 0; } 

beyond that, rust macros

  • can distributed compiled code
  • can overloaded in argument counts
  • can match on syntax patterns braces or parens or commas
  • can require repeated input pattern
  • can recursive
  • operate @ syntax level, not text level

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -