简体   繁体   中英

Is there an quick way to eliminate unused types in a C program in Visual Studio?

I have a large body of C code (dozens of files that are several thousand lines each) that I'm trying to port from another platform to MSVC++. There are many redundant types in a file because of sloppiness of previous programmers.

Obviously I can eliminate the types one by one and see if they build. Is there a quick way in Visual Studio that I can identify or refactor out unused types?

typedef struct {
    int Field1;
    int Field2;
} notused1;

struct notused2 {
    int Field1;
    int Field2;
};

int ActualWork() {
    // Doesn't use either struct
}

I don't believe this question is a duplicate of 2380153 because that question was asked in 2010.

In Visual Studio, you can deprecate all the symbols and get warnings for each used symbol. Then remove all deprecation off from used symbols, and the rest are not used.

like this:

#pragma deprecated(X)
struct X {  // will result C4995 warning in visual studio when using this struct
};

You can also use __declspec(deprecated) like this:

struct __declspec(deprecated) X {

};

look here and here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM