Forum Stats

  • 3,758,167 Users
  • 2,251,349 Discussions
  • 7,870,085 Comments

Discussions

warn_unused_result attribute works in C++ but not C?

nemequ
nemequ Member Posts: 5

I just noticed that sunCC in 12.6 supports the warn_unused_result attribute (yay!), but not suncc. It seems like an odd restriction; is it intentional?

Quick test case:

__attribute__((__warn_unused_result__))

int test_unused_result(void) {

  return 1729;

}

int main(int argc, char* argv[]) {

  (void) argc;

  (void) argv;

  test_unused_result();

  if (test_unused_result() != 1729)

    return EXIT_FAILURE;

  return EXIT_SUCCESS;

}

Best Answer

  • Maxim Kartashev-Oracle
    Maxim Kartashev-Oracle Member Posts: 64
    edited Feb 26, 2018 3:49AM Accepted Answer

    Front-ends of all three Studio compilers (CC, cc and f90) are totally separate, so while some features such as pragmas, attributes, or compiler options are supported by all compilers, others are not.

    The warn_unused_result attribute was implemented in the C++ compiler a couple of years ago because there was a demand for it in a large open-source application. We can log an enhancement request to support this attribute for the C compiler in the next version.

Answers

This discussion has been closed.