[ltt-dev] [LTTV PATCH] Fix warnings int the lttv/sync directory

Mathieu Desnoyers compudj at krystal.dyndns.org
Tue Jan 25 10:23:35 EST 2011


* Yannick Brosseau (yannick.brosseau at gmail.com) wrote:
> On 2011-01-24 19:58, Benjamin Poirier wrote:
> > On 24/01/11 01:05 PM, Yannick Brosseau wrote:
> >> Mostly wrong usages of g_error
> >>
> > [...]
> >> @@ -550,7 +550,7 @@ static void analyzeMessageEval(SyncState* const
> >> syncState, Message* const
> >>       message)
> >>   {
> >>       AnalysisDataEval* analysisData= syncState->analysisData;
> >> -    MessageStats* messageStats;
> >> +    MessageStats* messageStats = NULL;
> >
> > I'd like to mention that the warning
> > sync/event_analysis_eval.c:553: warning: ‘messageStats’ may be used
> > uninitialized in this function
> >
> > goes away when you configure and compile with CFLAGS=-O0 so I thought
> > it might be a compiler glitch. Any insight on that?
> >
> 
> Probably that without reordering, the compiler is able to see that the
> variable is not really used before initialization. (When you inspect the
> code you see that in the current state, it does not cause a problem.)
> 
> But anyway, it's always a better habit to always initialize variable to
> sane values when they are declared.

In C99, it's actually a better practice to declare your variables in
localized scopes as much as possible (at the beginning of blocs).

Initializing variables when not necessary may add overhead, and has the
downside to hide the compiler warnings (hiding cases where we should
have done dynamic initialization). I would recommend not to initialize
too much just for fun: in cases like here, we can add the NULL
initialization along with a comment saying that we do so to tell gcc
that it's ok.

Thanks,

Mathieu

> 
> Yannck
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




More information about the lttng-dev mailing list