Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1259

"typedef" should be used for function pointers

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Define and use a "typedef" for XXX
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Covered Languages:
      C, C++, Objective-C
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      15min

      Description

      Function pointer syntax can be hard on the eyes, particularly when one function is used as a parameter to another. Providing and using a typedef instead (or a using in C++) can make code easier to read, and should be preferred.

      Noncompliant Code Example

      extern void (*signal(int, void(*)(int)))(int);
      

      Compliant Solution

      typedef void (*SignalHandler)(int signum);
      extern SignalHandler signal(int signum, SignalHandler handler);
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                freddy.mallet Freddy Mallet (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: