Skip to contentSkip to conversation

vl: simplify code for main()

PATCH Applied Chen Gang 3 participants 5 messages Apr 15, 2014 – Apr 25, 2014

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

v2 cover vl: simplify code for main()

In "vl.c", at least, we can simplify the code below, so can let readers read professional C code (especially for new readers, which often start reading code at main function).

- Remove useless 'continue' in main().

- Eliminate a superfluous local variable in main().

---
 vl.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
author
#1 lore raw

PATCH v2 1/2 vl: Remove useless 'continue'

"This if else has no code between it and the end of the enclosing while loop. This makes this continue redundant."

---
 vl.c |    1 -
 1 file changed, 1 deletion(-)
vl.c +0 -1
index 9975e5a..7505002 100644
@@ -3034,7 +3034,6 @@ int main(int argc, char **argv, char **envp)
         if (argv[optind][0] != '-') {
             /* disk image */
             optind++;
-            continue;
         } else {
             const QEMUOption *popt;
 
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH v2 2/2 vl: Eliminate a superfluous local variable

In reply to Chen Gang

CODING_STYLE frowns upon mixing declarations and statements. main() has such a declaration. Clean up by eliminating the variable.

---
 vl.c |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
vl.c +9 -9
index 377f962..d381443 100644
@@ -4368,15 +4368,15 @@ int main(int argc, char **argv, char **envp)
 
     qdev_machine_init();
 
-    QEMUMachineInitArgs args = { .machine = machine,
-                                 .ram_size = ram_size,
-                                 .boot_order = boot_order,
-                                 .kernel_filename = kernel_filename,
-                                 .kernel_cmdline = kernel_cmdline,
-                                 .initrd_filename = initrd_filename,
-                                 .cpu_model = cpu_model };
-
-    current_machine->init_args = args;
+    current_machine->init_args = (QEMUMachineInitArgs) {
+        .machine = machine,
+        .ram_size = ram_size,
+        .boot_order = boot_order,
+        .kernel_filename = kernel_filename,
+        .kernel_cmdline = kernel_cmdline,
+        .initrd_filename = initrd_filename,
+        .cpu_model = cpu_model };
+
     machine->init(&current_machine->init_args);
 
     audio_init();
Signature · 1 line
1.7.9.5
#4 lore raw
In reply to Chen Gang
Quoted 7 lines · Chen Gang

In "vl.c", at least, we can simplify the code below, so can let readers read professional C code (especially for new readers, which often start reading code at main function).

- Remove useless 'continue' in main().

- Eliminate a superfluous local variable in main().

Applied to -trivial, thank you!

/mjt