Hi Martin, > > Don't assign the status here. We don't wanna do that. This way you are > > hiding potential uninitialized cases that otherwise the compiler would > > catch for us. > I cannot fully understand it. How can compiler find for us?
with GCC and the special set of options we use, the compiler will warn us if you use a variable without setting it. However that only works if you not initialize it when declaring it. Let me make an example. int err; if (condition) err = 10; return err; This will make the compiler warn about it and gives you a clear hint that you haven't spent enough time thinking about your code. If you would do "int err = 0;" then this warning never shows up and you potentially hide coding mistakes. > I think normally, to the uninitialized variable, it can only be found at > running time with wired error. The compiler will find it at runtime, > If fact, I was told to initialized variable immediately in the beginning of > learning coding. I know that they still teach that. Don't ask me why, it is actually a pretty bad idea. We really should make use of all the advanced warnings a GCC is capable of. > In you codes, I found sometime, the variable is initialized, some not. Do we > have some criteria that when need to initialize and when does not need. I prefer to NOT initialize the variable. However in some minority cases it makes sense. You will get a feeling for it at some point. However the general rule is not to initialize variables when declaring them. > > Putting this into a separate function doesn't make sense here. Just put > > it directly into the init function with a small comment that it is there > > to process the initial/current RFKILL states. > > > > Also you can do things like this: > > > > /* Process current RFKILL events sent on device open */ > > while (rfkill_process(chan) == G_IO_STATUS_NORMAL); > I buy in your idea, although not be fully persuaded. ;-) I know that this while loop looks kinda strange on the first view, but it is pretty obvious. Especially with the comment above. Regards Marcel _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman