How is read-only memory implemented in C?

That’s not a feature of the C language but a feature of the compiler/linker and the operating system working together. When you compile such code the following happens: The compiler will put the string into a read-only data-section. The linker collects all the data in such read-only sections and puts them into a single segment. … Read more

When, if ever, should we use const?

I believe the only time “const” is appropriate is when there is a spec that you’re coding against that is more durable than the program you’re writing. For instance, if you’re implementing the HTTP protocol, having a const member for “GET” is appropriate because that will never change, and clients can certainly hard-code that into … Read more

Oracle – How to create a readonly user

A user in an Oracle database only has the privileges you grant. So you can create a read-only user by simply not granting any other privileges. When you create a user CREATE USER ro_user IDENTIFIED BY ro_user DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp; the user doesn’t even have permission to log in to the database. … Read more

How to get around lack of covariance with IReadOnlyDictionary?

You could write your own read-only wrapper for the dictionary, e.g.: public class ReadOnlyDictionaryWrapper<TKey, TValue, TReadOnlyValue> : IReadOnlyDictionary<TKey, TReadOnlyValue> where TValue : TReadOnlyValue { private IDictionary<TKey, TValue> _dictionary; public ReadOnlyDictionaryWrapper(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) throw new ArgumentNullException(“dictionary”); _dictionary = dictionary; } public bool ContainsKey(TKey key) { return _dictionary.ContainsKey(key); } public IEnumerable<TKey> Keys … Read more

TypeScript return immutable/const/readonly Array

This seems to work… function getList(): ReadonlyArray<number> { return [1, 2, 3]; } const list = getList(); list[0] = 3; // Index signature in type ‘ReadonlyArray<number>’ only permits reading. Try it in the Playground ReadonlyArray<T> is implemented like this: interface ReadonlyArray<T> { readonly [n: number]: T; // Rest of the interface removed for brevity. }

Is there a difference between private const and private readonly variables in C#?

Well, you can use consts in attributes, since they exist as compile time. You can’t predict the value of a static readonly variable, since the .cctor could initialize it from configuration etc. In terms of usage, constants are burnt into the calling code. This means that if you recompile a library dll to change a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)