Go Back > Great Internet Mersenne Prime Search > Software

Thread Tools
Old 2014-08-16, 15:19   #1
May 2014

3×11 Posts
Default 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:
../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",
/* 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,
    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)
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,
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.
Explorer09 is offline   Reply With Quote

Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with my prime95 result mickfolly Information & Answers 7 2016-07-24 17:54
GCC/compiler warnings Dubslow Programming 2 2016-02-27 06:55
Stopping Prime95 from Attempting to Transmit Frivolous Result jinydu Lounge 15 2007-01-05 14:12
Is this a normal Prime95 Result? adamj123 Software 1 2005-10-11 12:35
How to disable an unused computer? 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

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.