avrdude-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avrdude-dev] code restructuring - using C99 or not?


From: Axel Wachtler
Subject: Re: [avrdude-dev] code restructuring - using C99 or not?
Date: Sat, 21 Jul 2012 19:45:12 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1

On 20.07.2012 23:53, Hannes Weisbach wrote:
For example instead of writing
if(verbose>  x) // x is a developer-defined constant, for example 2
   fprintf(stder, ...);
one could write
if(verbose>  WARNING)
...

My intention would be to move the "if(verbose>SOMETHING)" into
the macro itself, this would make the code easier to read.

PRINT(WARNING, "foo=%d\n", 42);

In my opinion, this makes code much easier to read and it would be clear(er) to 
(new) developers which verbosity level to use for a certain message.

We should come up with severity list, e.g.

 ERROR   ... printed always
 WARNING ... printed even if "quite" is set
 INFO    ... normal print
 DEBUG1  ... -v
 DEBUG2  ... -vv
 DEBUG3  ... -vvv
 DEBUG4  ... -vvvv

Yes: __func__.

I tried __func__ .... cool, I did not know this :-)

On 20.07.2012 20:40, Weddington, Eric wrote:
Why do you need to encapsulate these statements behind a macro? (That then has 
to be written and then interpreted by developers when modifications are made...)
Well, there is no "need" as such. Apart from the argument with the usage in a 
library, I would argue less code. I don't think understanding of such a macro by 
developers poses a problem, if it's intention is documented in the source code (or if it 
is named properly).
Do you have other concerns than developers having to familiarize themselves 
with the code?

Since I crowled trough the code for replacing progname and progbuf, I think a macro that is calling a central printing function would be good. This function could handle all the formatting and prefixing with progname, __func__ and __LINE__ and even stuffing progbuf spaces after
a "\n".

My current approach uses a callback function with argument va_list.
But I saw that va_list is hard to handle if a python callback is used,
so I would prefer a callback function that gets a simple string and
all the formatting is done in the central printing function.

B.t.w. my local copy of avrdude now loads libavrdude.so into python
with ctypes. In the next step, functions need to be called ;-)

Cheers, Axel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]