Magic numbers are unexplained values that often should be replaced with a named constant.
Questions tagged [magic-numbers]
193 questions
1
vote
2 answers
Type-alias for enumeration
I am working with some code that uses values from an enumeration class (extending uint8) to access matrix columns "by name" rather than by a hard-coded number. The reason for this approach is that matrices are perceived as more performant compared…

Dev-iL
- 23,742
- 7
- 57
- 99
1
vote
1 answer
What is ObjectStreamConstants.STREAM_MAGIC?
I refer to ObjectStreamConstants.STREAM_MAGIC in the interface ObjectStreamConstants, which is defined in the JDK source like so:
/**
* Magic number that is written to the stream header.
*/
final static short STREAM_MAGIC = (short)0xaced;
What is…

CuriousMind
- 8,301
- 22
- 65
- 134
1
vote
1 answer
How to load .tif raster files in R
I am currently working on some raster models. My code has generated about 4k models (all .tif files), but about 10% of these cannot be opened using load("insert path"). I have tried readr(), readRDS() and source(), none of which worked. I have also…

tungphung
- 11
- 1
- 2
1
vote
5 answers
Does the concept of "magic number" change from language to language?
Take the following code in C/C++, for example:
int foo[] = {0, 0, 0, 0};
No magic numbers, right?
Now, the Python "equivalent" of that would be:
foo = [0, 0, 0, 0]
Still no magic numbers.
However, in Python, that same thing can be written like…

Gerardo Marset
- 803
- 1
- 10
- 23
1
vote
2 answers
C++ - Put const magic numbers into namespace or not
I always used #define to define magic numbers somewhere at the beginning of the the cpp file. I want to change that to const numbers. (globals declared / defined in the cpp file.) Is this a good idea? Should I put them into anonymous namespace? I…

Newline
- 769
- 3
- 12
1
vote
1 answer
Where to store plain text (magic strings) in Angular
In my Angular application I want to set simple error/notification messages in my controller. An example of this uses the Material Snackbar for Angular:
this.snackBar.open(
'Order successful',
'OK',
{ duration: 2500 }
);
My problem is now,…

Marius Lichtblau
- 11
- 1
- 3
1
vote
6 answers
How to avoid magic-numbers in shell?
I always write some magic numbers in my interactive shells and shell scripts.
For instance, If I want to list my users's names and shells, I'll write
cut --delimiter=: --fields=1,7 /etc/passwd
There exist two magic-numbers 1,7. And there are more…

xiang
- 1,384
- 1
- 12
- 28
1
vote
0 answers
Magic numbers in Bitcoin Block printing something different
I am trying to decode the bitcoin block, but when I am trying to read magic number which are first four bytes , it is showing me some different result then 0xD9B4BEF9. can anyone help me with this issue? My code is as follows:
fs =…

Tabz
- 137
- 1
- 11
1
vote
0 answers
PE - DOS signature (MZ) and Little Endian
this is not a serious problem but I am curious why DOS signature is 0x5A4D not 0x4D5A
DOS Header's first member is MZ which is DOS signature named by Mark Zbikowski.
Below code is the part of DOS header.
typedef struct _IMAGE_DOS_HEADER {
WORD…

TyeolRik
- 466
- 2
- 25
1
vote
1 answer
Invalid magic number of a png file
I am trying to verify if a link is a valid image with magic number. Most of the images link work fine. But here are set of images on trump's site that does not produce correct magic numbers, though they appear to work fine on browser. Magic number…

Yalamber
- 7,360
- 15
- 63
- 89
1
vote
1 answer
Is there any collection of 'magic' headers of filetypes which is compatible with Unix `file` Command?
I am trying to find a magic header collection of file types which can be feeded to file command using file -m but no avail.
Distro pre included file heaers are not too many to detect all the file types on the internet..
Has anyone come up with any…

Phyo Arkar Lwin
- 6,673
- 12
- 41
- 55
1
vote
2 answers
Why there is no 16-bit information in ELF magic number?
In ELF-header, value of e_ident[EI_CLASS] can either be 1 or 2, which indicates 32-bit operating or 64-bit operating system. But from history we know that ELF first appeared in Solaris 2.0, which is released in 1993. However, widely used 32-bit…

JiangFeng
- 355
- 2
- 14
1
vote
4 answers
Does a C source-code/script/program uses a shebang-like command?
might be a stupid question but I'll try anyway:
when you turn a shell-script into an executable, it uses the shebang to knows which interpreter to use when you run it. Does a C code/script/program uses/has something similar?
are there any magic…

Maverick Meerkat
- 5,737
- 3
- 47
- 66
1
vote
1 answer
How to remove error : bad restore file magic number (file may be corrupted) -- no data loaded?
Using R version 3.3.0 (Windows)
Error: bad restore file magic number (file may be corrupted) -- no
data loaded
In addition: Warning message: file ‘.RData’ has magic number 'q' Use
of save versions prior to 2 is deprecated
During startup -…

Animesh Kumar Paul
- 2,241
- 4
- 26
- 37
1
vote
1 answer
could not launch process: invalid magic number in record at byte 0x0 Delve Golang
Just got a:
could not launch process: invalid magic number in record at byte 0x0
When running on OSX after working fine for a while:
dlv debug main.go
reinstalled Delve, but still persists. What can it be?

juan Isaza
- 3,646
- 3
- 31
- 37