Skip to main content
98 votes
Accepted

Is it a security vulnerability to declare class members as public?

Access modifiers like public/private/protected are not intended as a security boundary. And since C++ is not a memory-safe language, this cannot be a security boundary. The laziest “attack” to access ...
amon's user avatar
  • 136k
14 votes

Is it a security vulnerability to declare class members as public?

Using public and private correctly (and following good practices in general) helps you write better code with fewer bugs, and code with fewer bugs is typically harder for an attacker to exploit. ...
forest's user avatar
  • 414
10 votes

Why does C not support direct array assignment?

C originally came from a predecessor language called B, made by Ken Thompson. In B, there were no types. Everything was a "word" (basically, an int). In B, arrays were just pointers to the ...
Min4Builder's user avatar
9 votes
Accepted

Why does C not support direct array assignment?

Why does C not support direct array assignment? It is arguably a shortcoming, due to missing features around arrays, but one the original designers choose not to resolve.  Add in the (over) emphasis ...
Erik Eidt's user avatar
  • 34.8k
8 votes
Accepted

Why List<T>.Enumerator is struct?

According to a video from a conference session called "Writing Allocation Free Code In C#", the Net Core team is taking efforts to reduce unnecessary object allocations. Since struct is a "Value" ...
Berin Loritsch's user avatar
8 votes

Is it a security vulnerability to declare class members as public?

Private and protected do not provide any security at all. Why? Because they are in your source code. They only affect code written by someone with access to your source code. If I have access to your ...
gnasher729's user avatar
  • 49.4k
8 votes
Accepted

Few unusual C/C++ declarations

But nowhere in the code the actual Enum had been defined by something like EnumKeys test; For the enumeration, there may never be any declaration of a variable of that type, but it may be used for ...
user1118321's user avatar
  • 4,981
7 votes

Is it a security vulnerability to declare class members as public?

I have always wondered whether public, protected, and private has security implications post compilation. Since you're asking about C++, I'd say the answer is "not per se" (unless this ...
Zoë Sparks's user avatar
3 votes

Is it a security vulnerability to declare class members as public?

No Reason: Once compiled, private, protected and public are gone. In C++, you can think about these keywords as nothing more or less than directives to tell the compiler that certain member accesses ...
cmaster - reinstate monica's user avatar
3 votes

Struct or class for wrapping an int when 0 isn't a valid value

To be more precise at the valid values: they have to have 5 or 6 digits. The first 4 can have any value between 1000 and 9999, the remaining digit(s) are either between 1 and 4 or 1 and 12 Given these ...
David Arno's user avatar
  • 39.6k
2 votes
Accepted

Struct or class for wrapping an int when 0 isn't a valid value

In a comment, you wrote with a struct I didn't need to explicitely implement equality and I didn't have to do null checks. Therefore I'd prefer a struct. If the requirement is just to wrap an int, ...
Doc Brown's user avatar
  • 221k
2 votes

Struct or class for wrapping an int when 0 isn't a valid value

You need a requirements review. Not every integer value is valid This is a very weak requirement. There is no computer in existence for which this isn't true. Some ints are so long they'd fill ...
candied_orange's user avatar
2 votes

Is it a security vulnerability to declare class members as public?

For public/protected/private to be making a difference, you would have to be allowing someone to compile and link their C++ code against your headers & binary. If someone already has that much ...
Ben's user avatar
  • 1,047
1 vote

Is it a security vulnerability to declare class members as public?

Security implies that you wish to protect something. Anyone with the right tools can disassemble the binary, look at what is being done, and, with enough time and experience, can reasonably infer the ...
Fabian Sievert's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible