Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-04-2014, 11:03 PM   #1
mohammad taqy bayat
LQ Newbie
Registered: Aug 2014
Posts: 16

Rep: Reputation: Disabled
format warnings in linux and unix

Hi there,
While compiling a makefile on ubuntu 12.04 LTS (64-bit) encountered with these error:

m_lea_user.c: In function ‘main’:
m_lea_user.c:168:2: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘CHARS (*)[64]’ [-Wformat]
m_lea_user.c:258:7: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat]
m_lea_user.c:318:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long int’ [-Wformat]
m_lea_user.c:318:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘long unsigned int’ [-Wformat]
m_lea_user.c:394:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat]
m_lea_user.c:395:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat]

Here is the m_lea_user.c:

/* */
/*+ CALLING : m_lea_user */
/* */
/* This working template accepts a few steering */
/* parameters, opens an input source and optional */
/* output file and reads events. */
/*+ Version : 1.01 */
/*+ Author : H.G.Essel */
/*+ Created : 01-mar-2000 */
/*+ Updates : Date Purpose */
/* */
/* A.Kozela : 29.07.2000 getting MBS data via TCP from rio2eth1 */
/* */
#include <stdio.h>
#include <string.h>
#include "typedefs.h"
#include <sys/time.h>
#include <unistd.h>

#define F__SWAP(ps,l,pd) f_swaplw((int *)ps,(int)l,(int *)pd)

#define UNIXENV 1 /* switch UNIX or VMS */
#define ENDIAN 0 /* little endian */
#define _ALL_SOURCE /* for types.h typedef u_char...*/

#include "gps_sc_def.h" /* must be first */
#include "clnt_buf_def.h"
#include "s_filter.h"

#if ENDIAN == 1 /* big ENDIAN ? */
#include "s_flt_descr_swap.h"
#include "s_opc1_swap.h"
#include "s_pat_swap.h"
#include "s_clnt_filter_swap.h"
#include "s_bufhe.h"
#include "s_ve10_1.h"
#include "s_ves10_1.h"
#else /* ENDIAN == 0 */
#include "s_flt_descr.h"
#include "s_opc1.h"
#include "s_pat.h"
#include "s_clnt_filter.h"
#include "s_bufhe_swap.h"
#include "s_ve10_1_swap.h"
#include "s_ves10_1_swap.h"
#endif /* ENDIAN */
#include "s_evhe.h"
#include "s_filhe.h"
#include "f_evt.h"
#include "f_swaplw.h"
//#include "DixCommons.h"
#include "OutBuf.h"
#include "out_pipe.h"

extern comm_buff com_tf;
extern CtrlFlags ctrl_flags;

extern int OUT_ON;

//extern long int init_anal_(void);

long HSM_RANG; /* only for compatibility with acquisition program */
char PIPE=0;

main(int argc, char **argv)
s_evt_channel s_gl_chan_i, s_gl_chan_o1;
s_ve10_1 *mbs_eve=NULL;
s_ves10_1 *mbs_seve=NULL;
s_filhe *ps_filhe=NULL;
s_bufhe *ps_bufhe=NULL;
INTS4 ll, l_evts=0;
long *p_data, li, tot_len=0, l_len=0, lbuf[2], shortsread,true_len, *pl=NULL;
long Startsec=0, Startnsec=0, Usec=0, Unsec=0,longs2read,longsread;
long total_memory=0, total_periodic=0, total=0;
struct timeval tv;
char txt1[64], txt2[64];
short swap, *sbuf,i,noss, i_fil, n_all_fil, OUT_TYP=0;
static int TCP_info=0, TRIG_info=0, MEM_error=0;
/* arguments with defaults: */
INTS4 l_server=GETEVT__FILE, l_events=1000;
INTS4 l_out=0, l_print=0, l_anal=0, l_dump=0;
CHARS c_source[64],c_output[64],c_args[64],c_type[64];
CHARS c_evef[64], a_evef[64][128], c_dum[64];
FILE *fin;

sbuf = (short *)lbuf;

if(argc != 1)
/* args for this test program: */
/*input events [output] [-trans -stream -event -file -out -print -anal -dump]*/

In DP2 off line analysis arguments to the program can have the form:

no arguments - program reads file names from file ReadData.inp,
event number is set to 100000000
input_file - program reads events from the specified file,
event number is set to 1000
input_file events - as above, but reads specified number of events

//fprintf(stderr,"\n Number of arguments %d\n", argc);
//for(ll=0; ll<argc; ll++) fprintf(stderr," argv[%d]= %s\n",ll,argv[ll]);
if(argc > 3)
if(strstr(argv[3],"-") == NULL)
if(argc > 2)
if(strstr(argv[2],"-") == NULL)
if(argc > 1){
//fprintf(stderr,"Not implemented\n");
fprintf(stderr,"Output to pipe \n");


for(ll=1;ll<argc;ll++) strcat(c_args,argv[ll]);

if(strstr(c_args,"-o") != NULL) l_out=1;
if(strstr(c_args,"-p") != NULL) l_print=1;
if(strstr(c_args,"-a") != NULL) l_anal=1;
if(strstr(c_args,"-d") != NULL) l_dump=1;

for (i=0; i<=64; i++) a_evef[i][1] = c_evef[i];
n_all_fil = 1;
else {}

// we do this independently on the number of arguments:
//fprintf(stderr,"\t c_source: %s\n", c_source);
fin = fopen("ReadData.inp","r");
if (fin == NULL){
fprintf(stderr,"\n\nNo input file ReadData.inp found ! \n\n");
i_fil = 1;

168: while (fscanf(fin, "%s", &c_evef) != EOF){
for(i=0; i<=64; i++) a_evef[i][i_fil] = c_evef[i];
for(i=0; i<=64; i++) c_dum[i] = a_evef[i][i_fil];
//fprintf(stderr,"line # %3d file name %s \n", i_fil, c_dum);
if (i_fil > 128) break;
n_all_fil = i_fil-1;
if (n_all_fil==128)fprintf(stderr,"\n maximal number of files read \n");
fprintf(stderr,"\nNumber of file names read in %d \n", n_all_fil);

/* Initialize your analysis if necessary */

OUT_TYP = init_out();

fprintf(stderr,"\n can't open PIPE");

/* Loop over input files */

for (i_fil=1; i_fil<=n_all_fil; i_fil++)
for(i=0; i<=64; i++) c_evef[i] = a_evef[i][i_fil];

/* Open input and output channels */

if(f_evt_get_open(l_server, c_source, &s_gl_chan_i,
(CHARS **)&ps_filhe,0,0) != GETEVT__SUCCESS)
fprintf(stderr,"Error opening channel %s\n",c_source);
// kvi_exit();
// exit(1);
goto nextf;
fprintf(stderr,"Opened input from %s %s, for %d MBS_buffers\n",
if(l_out == 1)
/* 32 spanning buffers, size 32768, type 10, subtype 1 */
// MUST match definition of EV_BUF_LEN and N_EV_BUF from 'setup.usf'
// configuration file of MBS
if(f_evt_put_open(c_output, 32768, 32, 10, 1, &s_gl_chan_o1, NULL)
printf("Error opening output channel %s\n",c_output);
fprintf(stderr,"Opened output file %s\n", c_output);
/* Event loop */
gettimeofday(&tv, 0); // for rate measurement
Startnsec = tv.tv_usec; // for rate measurement
if(f_evt_get_event(&s_gl_chan_i, (INTS4 **)&mbs_eve,
(INTS4 **)&ps_bufhe) != GETEVT__SUCCESS){
fprintf(stderr,"Last event %d\n", ll);
gettimeofday(&tv,0); Unsec = (tv.tv_usec-Startnsec)/1000;
Unsec = (Unsec>=0) ? Unsec : 1000 + Unsec;
258 : if(TCP_info) fprintf(stderr, "\n For TCP used %3d msek.",Unsec);

p_data = (long *)mbs_eve;
mbs_seve = (s_ves10_1 *)(mbs_eve+1);

pl = (long *)(mbs_seve+1);

if(l_out == 1)
f_evt_put_event(&s_gl_chan_o1, (INTS4 *) p_data);

swap = 1;

if(!(ll%100)) fprintf(stderr,"Event %d\n", ll);

if(TRIG_info) fprintf(stderr," Trigger type: %d\n",mbs_eve->i_trigger );

//fprintf(stderr,"size of com_tf.out_buf %d \n", sizeof(com_tf.out_buff[0])/2);

shortsread = 0; noss=0;
longs2read = 0;
longsread = 0;
tot_len = *(p_data+4)-4; // plus headers and length words
/* fprintf(stderr,"pdata %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
*(p_data), *(p_data+1), *(p_data+2),
*(p_data+3),*(p_data+4),*(p_data+5),*(p_data+6),*(p_data+7), *(p_data+8),
*(p_data+9),*(p_data+10),*(p_data+11),*(p_data+12),*(p_data+13), *(p_data+14) );
total += mbs_eve->l_dlen;
switch (mbs_eve->i_trigger)
case 1:
case 2:
case 5:
case 6:
total_memory += tot_len;

for(i=0; i<1; i++)
l_len = *(p_data+8+longsread) + 4; // +4: header & len
longs2read = (l_len %2)? l_len/2+1 : l_len/2;

//fprintf(stderr, "SYS %d Len %d\n",i, l_len);

if((out2stderr(p_data+7+longsread, l_len, swap, i) != i) && OUT_ON != 0)
fprintf(stderr,"Subsystem %d not present. Reset VME Crate\n",i);

com_tf.out_buf_len[i] = l_len; // in 4 byte words
if(l_len < sizeof(com_tf.out_buff[0])/2)
memcpy(&(com_tf.out_buff[i][0]),(void *)(p_data+7+longsread),
fprintf(stderr, "Subsystem %d doesn't fit (%d) in out_buf %d\n",
318 : i, l_len, sizeof(com_tf.out_buff[0])/2);
// goto exi1;
goto nextf;
longsread += longs2read;

if(noss != 1 && (OUT_TYP == 1 || OUT_TYP == 2))
fprintf(stderr,"Only %d sybsystem(s) present.",noss);
fprintf(stderr," Restart VME Crate");
// goto exi1;
goto nextf;
if(analyze() == -1)
fprintf(stderr,"Too many lost words in subsystems.");
fprintf(stderr," Restart VME Crate");
// goto exi1;
goto nextf;
MEM_error = 0;

case 4:

total_periodic += tot_len;
l_len = *(p_data);
// fprintf(stderr, "SYS %d Len %d\n",i, l_len);
//for (li=0;li<64;li++)
//fprintf(stderr, "%8x%c", *(p_data+li), ((li+1)%8)?' ':'\n');

if((*(p_data+7) == 0xaaa1aaa1)||(*(p_data+7) == 0xbbb1bbb1))
goto HSM;
// nie rozumiem l_len = *(p_data+4)-2; // plus header and length word
l_len = *(p_data+4); // plus header and length word
// fprintf(stderr, "SYS %d Len %d len %x\n",i, l_len, l_len);

out2stderr(p_data+7, l_len, swap,0);
com_tf.out_buf_len[0] = l_len; // in 4 byte words
memcpy(&(com_tf.out_buff[0][0]),(void *)(p_data+7), l_len*2);
} // End of loop over events


fprintf(stderr,"\n end of file %s\n", c_evef);

} // End of loop over files


/* closing of analysis */

if(l_out == 1)
fprintf(stderr, "\nDAQ Events: %d \n", l_evts);
394 : fprintf(stderr, " words from memories : %d \n", total_memory);
395 : fprintf(stderr, " words from periodics: %d \n", total_periodic);


please help me to solve them.
Thanks in advance.

Last edited by mohammad taqy bayat; 09-04-2014 at 11:26 PM.
Old 09-05-2014, 12:25 AM   #2
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
These look like warnings to me, not errors. Unless you're compiling with the -Werror flag to gcc, they should not stop compilation. Fixing them is not an easy task -- it looks like the problem is that this code was written rather sloppily. It would probably work as written, but without some further anlaysis, it's hard to say for sure. The warnings are fairly clear about what's wrong. My C is rather rusty, but it seems fairly straightforward. Mostly whoever wrote this code is being sloppy about the types of arguments being passed into fscanf and fprintf. The types of the variablea being passed in should match the format stering, as the compiler tells you.

Was this code you wrote yourself or third party? If the latter, it might be best to bug the original author (if available) to see if there is a newer version where this is fixed.
Old 09-05-2014, 09:41 AM   #3
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
They are valid errors... depending on the system. The integer errors can be corrected by replacing %d with %l.
The long unsigned errors by %lu.

Now most of these errors would only show up if the number is too large (unsigned being treated as signed) and numbers that should be positive are suddenly negative (the error).

Most such changes can be identified from the printf type specification table:

The problem with "CHARS (*)[64]" is the problem of what CHARS is - a structure? Even if CHARS is "char" (via macro definition), you can't print an array of 64 pointers using a %s (which only allows for char *, or char array[]).

It almost looks like a missing subscript somewhere.

It would have been useful to have the line numbers included in the code listing... and using code blocks to prevent it from being misformated.

Last edited by jpollard; 09-05-2014 at 09:44 AM.


c++, formating

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] SAN volume : Partition & format or direct format rrmavani Linux - Server 1 03-07-2013 03:04 AM
[SOLVED] can't debug with gdb: not in executable format: File format not recognized (squeeze) oddiofile Debian 1 08-24-2010 04:21 AM
Best video format for YouTube upload and can Recordmydesktop output that format? linus72 Linux - Software 6 12-21-2009 04:53 PM
[SOLVED] Simple Linux script to convert datetime format to UTC format shayno90 Linux - Newbie 10 10-09-2009 09:19 AM
Format Problems Saving Star Office Docs in Word Format kkempter Linux - Software 4 08-27-2003 05:23 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration