195 questions
1 vote
2 answers
220 views
Why is initializing a struct field with a default value considered a 'magic-number' by clang-tidy? [closed]
Consider the following example: struct DefaultSettings { std::string tcpIpAddress = "127.0.0.1"; uint16_t tcpPort = 1993; // Marked as magic number! } clang-tidy (with readability-magic-...
4 votes
3 answers
174 views
Does casting a magic address to a pointer in C violate strict aliasing rules?
I know the following code violates strict aliasing rules int object = 10; int *pi = &object; // OK float *pf = (float *)pi; // OK float f = *pf; // undefined behavior In the header files of ...
1 vote
1 answer
325 views
What's the magic number 0xa282ead8 seen in many CRC implementations?
I see the magic number 0xa282ead8 in many CRC implementations, like https://github.com/kubo/snzip/blob/master/crc32.h I don't understand CRC calculation very well. What's the effect of this number and ...
0 votes
3 answers
410 views
Is there a standard way to define a big list of "magic numbers" or parameters? [duplicate]
Abstractly, say you were building a physics simulation and needed many universal constants or typical values for things like mass. It feels like there should be a standard approach to implementing ...
3 votes
2 answers
1k views
What is the problem with assigning magic numbers to named structure members?
Consider the following code: const double Motor_Kv = 1.1e5; // Motor constant, [rpm/V] const double Motor_R = 2e-2; // Winding resistance, [Ohm] const double Motor_J = 3e-6; // Rotor angular mass, ...
1 vote
0 answers
1k views
python compiled bytecode `.pyc` not compatible with every versions. can we make it general? How to remove python magic number error?
I have compiled this visible_code.py file into .pyc compiled byte code file, then I am running the function fun from .pyc file. # visible_code.py def fun(): print("Hello") # convet to ...
0 votes
1 answer
154 views
Jest magic number comparison failing in expect...toBe
I'm testing to ensure a Buffer's magic number is zip format. I'm doing this by extracting the buffer's first 4 bytes to string and comparing against the magic number for zip which is PK. const ...
0 votes
1 answer
42 views
Preventing magic numbers used in firebase realtime database
So I want to specify a time after which a post gets deleted. The time is 3 months, in my code I would define this as const THREE_MONTHS_IN_MS = 7889400000 export const ...
0 votes
0 answers
319 views
Fast inverse square root in python on float32
I have done some checks for the fast inverse square root method in python (jupyterlab using python version 3.8.8) and for some reason then I've come to the conclusion that I must either be doing ...
0 votes
1 answer
1k views
Avoiding checkstyle MagicNumber error when filling object with magic numbers
I use magic numbers in class member initialization: private static final RangeMap<Integer, String> MY_MAP = new ImmutableRangeMap.Builder<Integer, String>() .put(Range.closed(10, ...
0 votes
0 answers
191 views
searches for files using the magic number of the file header
I'm doing an exercise: write a C program for Linux that searches for files in ELF, PE32, COFF and a.out formats using the magic number of the file header. I tried writing my own program to find magic ...
2 votes
1 answer
2k views
Magic number in files Linux. C programming
I want to get the Magic Number from a binary file (for example file ELF hava 7f 45 4c 46). I wrote a program to print out the magic number of the file but i get the error zsh: segmentation fault ./...
1 vote
0 answers
51 views
Should I declare a number as constant if it is passed as a parameter to a meaningful named function?
Suppose we a validation code similar to the following: Rule(account => account.CompanyName).MaxLength(50) Or Rule(account => account.Balance).MustBeGreaterThan(0) Do we still call the numbers ...
6 votes
2 answers
7k views
How to check type of files using the header file signature (magic numbers)?
By entering the file with its extension, my code succeeds to detect the type of the file from the "magic number". magic_numbers = {'png': bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, ...
1 vote
1 answer
1k views
Flutter: how to get magic numbers of file?
I'm using file_picker to choose file from storage and sometimes it doesn't give an extension but I need to know an extension to send it to server side. I'm going to identify it by Magic Number like ...