On 05/23/2017 09:56 PM, Wang Dong wrote: > > Hi guys, > > I am new to qemu. But I need do some job in it right now. > > When I try read qmp code. I found a interesting part against it. > > Some C source code is generate from json file. > > I wonder why this? What is the benefits of this?
Boring and repetitive code that is easy to typo is best written by a computer, which excels at boring and repetitive tasks. Writing our description in a more concise higher language and generating C code from that lets us focus on the actual design, rather than the mundane correctness of the code implementing the design. It's the same reason that people use bison/yacc rather than hand-written parsers for complex grammars - you isolate the correctness of the code to the correctness of the generator, and free yourself to now only have to worry about the bigger picture of the input you feed to the generator. And on another level, it's why we write programs in C instead of assembly. Abstraction is good. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature