mersenneforum.org Opinion about Prime95 compile warnings and -Wno-unused-result
 Register FAQ Search Today's Posts Mark Forums Read

 2014-08-16, 15:19 #1 Explorer09   May 2014 3×11 Posts Opinion about Prime95 compile warnings and -Wno-unused-result I tried to compile mprime 28.5 on Ubuntu (Linux) 14.04 for my own use. However GCC in Ubuntu's default setting generates many compiler warnings. Although I read the makefile which suggests they can be suppressed by -Wno-unused-result compiler flag, it still makes me curious to know what they're about. And I found out there are indeed code that I can consider bad practice, and the compiler did the right thing by generating warnings. One example: Code: ../ecm.c: In function ‘ecm_QA’: ../ecm.c:3568:3: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result] (void) fscanf (fd, "%lf,%lu,%lu,%ld,%lf,%lu,%lu,%lu,%s\n", ^ Code: /* Read a line from the file */ n = 0; (void) fscanf (fd, "%lf,%lu,%lu,%ld,%lf,%lu,%lu,%lu,%s\n", &k, &b, &n, &c, &sigma, &B1, &B2_start, &B2_end, fac_str); if (n == 0) break; ...... The code is supposed to parse a file (named 'qa_ecm'), but does not check whether the file can EOF at the middle of the line. The return code of fscanf can be used to do this, but here it is intentionally ignored. I think it will be better to rewrite it to something like this: (EOF at the middle of the line usually means file is corrupt, so return an error that way) Code: int rc; rc = fscanf (fd, "%lf,%lu,%lu,%ld,%lf,%lu,%lu,%lu,%s\n", &k, &b, &n, &c, &sigma, &B1, &B2_start, &B2_end, fac_str); if (rc < 9) { // Note: (rc != EOF) won't work! OutputStr (thread_num, "File corrupt.\n"); return (STOP_FILE_IO_ERROR); } Fixing all of these can take a lot of time, and I have little to help. But it's a bad idea to suppress there warnings - just keep them on (-Wunused-result) and we can easily spot bugs through them.

 Similar Threads Thread Thread Starter Forum Replies Last Post mickfolly Information & Answers 7 2016-07-24 17:54 Dubslow Programming 2 2016-02-27 06:55 jinydu Lounge 15 2007-01-05 14:12 adamj123 Software 1 2005-10-11 12:35 romanhoehne PrimeNet 1 2004-05-06 13:00

All times are UTC. The time now is 14:53.

Fri Jul 3 14:53:21 UTC 2020 up 100 days, 12:26, 2 users, load averages: 1.54, 1.33, 1.47