that is why I am uncomfortable with C. Pascal and JALv2 are both much=20 clearer. --Bob A -- On 5/3/2014 11:41 AM, PICLIST wrote: > As an experienced, but certainly not expert, C programmer - I have a few > tens of thousands of lines of C and C++ behind me, and more in other > languages. Unfortunately my experience is spread out over too many > languages, years, platforms and compilers. > > I tend to believe in always turning on all compiler warnings and write my > code to avoid all of the warnings. The code ends up a bit longer, but fix= ing > warnings has saved me from hours of debugging many times. > > The warnings usually tell you when you are playing around in the less > obvious areas of the language. I am then forced to code in an obvious > fashion so there is no question of what I want. > > In the current signed vs unsigned discussion, I would be forced to add an > explicit cast to "int" or "unsigned int" depending on what I wanted. The > cast makes the intention clear and reminds me in the future that the code= is > dealing with unlike types. In fact it makes me think about the possibilit= ies > for error in what I am doing. In the current example for instance: Am I s= ure > the int will never have a value greater than 16384? > > Another example where the warnings are very useful is the "=3D" vs "=3D= =3D" > operators: > > It is valid C (and maybe even intentional) to code the following: > > // b ends up as 2! > int a=3D1; > int b=3D1; > > if (a=3Db) { > b=3D2; > }; > > In most cases this will generate a warning about using the assignment "= =3D" > operator in an if, instead of the more common logical "=3D=3D" comparison > operator. The warning saves me from having to debug the problem because o= f a > typo. > > If I had really meant to do that, I would code: > > if (0 !=3D (a=3Db) { > b=3D2; > }; > > Or more clearly: > > a=3Db; > if (a) { > b=3D2; > }; > > I even put in the extra () in the first case to be clear on what operator > precedence I desire, since the precedence of =3D vs =3D=3D is not necessa= rily > obvious. Many people hate doing things like "=3D=3D 0" or "!=3D 0" in an = if, since > that is what the if does anyway, but any decent compiler will create th= e > same code, and the clarity of specifying the "=3D=3D 0" if often worth th= e extra > few characters. > > C can be a master of obfuscation. Obfuscation is certainly not the best > route to bug-free code. My favourite example is: > > #include > main(t,_,a) char *a; { > return!0 t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t=3D=3D2?_<13? > main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t, > "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/= #\ > ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \ > q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;= # \ > ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \ > iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \ > ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' '= )# > \ > }'+}##(!!/"):t<-50?_=3D=3D*a?putchar(31[a]):main(-65,_,a+1):main((*a=3D= =3D'/')+t,_,a > +1) > :0 "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1); = } > > The above is standard C and only generates one warning when I last compil= ed > it and really does do something. It certainly does something unexpected. > > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .