All Questions
Tagged with code-duplication c
13 questions
0
votes
0
answers
54
views
How can I avoid duplicate code in data structures?
In my c project I have 2 structs, and I need a basic dynamic array for each of them containing the same functions. How can I avoid duplicate code, since c doesn't have templates or generics?
0
votes
0
answers
62
views
how to remove code duplications in this code?
I am a new C99 programmer and want the help of the community on this one.
I wrote the following function which receives two pointers for a node (Or simply Node) and a pointer to a pointer to node (Or ...
-1
votes
2
answers
1k
views
Is there a way to avoid code duplication in multiple similar functions?
I am writing a family of functions which are to be embedded in a small micro-controller operating at very near real time, so every clock cycle counts. The functions are almost identical.
The only ...
1
vote
1
answer
45
views
Traversing binary search tree, how to advoid code duplication
I have been working on this small program. It reads data(members) from a file and stores it in a binary search tree. There are two features, print all the members and print all members but only with ...
4
votes
5
answers
588
views
Reducing code duplication in C program with nearly identical statements in if/else?
I am trying to reduce code duplication in my C program, where all the statements in each branch of an if/else block are identical, except for a function name and its arguments. The idea is that the ...
2
votes
2
answers
126
views
Is there a function equivalent that can take in statements as arguments?
I have the following section of code that I need to use about 5 times throughout the whole program, but with different lines of code in place of the comment.
while (loop_day < (day+1)) {
while ...
3
votes
2
answers
605
views
Best Practice - Consolidating duplicate text literals across many translation units
Our company's static analysis tool is stating that there are duplicated strings (text literals). The issue is that they are spread across many translation units (source files).
For example, the ...
0
votes
4
answers
163
views
optimizing switch case code
I have below switch case in my code.
switch(condition)
case 'A' :
//Code part A
break;
case 'B' :
//Code part A
//Code part B
break;
...
2
votes
2
answers
92
views
Avoid duplicating code when only the middle part of functions differ
I have a bunch of functions that all start and end the same way with only the middle part being different.
I know I could do:
int
foo(int bar)
{
intro();
/* stuff that differs */
outro();...
2
votes
6
answers
1k
views
C Programming: how to avoid code duplication without losing clarity
edit: Thanks to all repliers. I should have mentioned in my original post that I am not allowed to change any of the specifications of these functions, so solutions using assertions and/or allowing to ...
2
votes
3
answers
279
views
C: code duplication example
I'm writing functions that take the checksum of two different things: one, a file; and two, an archive entry a la the BSD libarchive library. I borrowed the checksum code from GNU's coreutils.
My ...
10
votes
6
answers
9k
views
I need a tool to find duplicates or similar blocks of text in a singular text file or set of text files
I want to automate moving duplicate or similar C code into functions.
This must work under Linux.
1
vote
2
answers
172
views
How can I remove the duplication between these C macros?
I have the following couple of C pre-processor macros for creating test functions:
// Defines a test function in the active suite
#define test(name)\
void test_##name();\
SuiteAppender test_##...