57,257 questions
Score of 0
2 answers
116 views
Is it safe to assume pointers will only have information in their bottom 48 bits?
Pointers to userspace on x86_64 must start with 0x000, covering 12 of the 64 bits and leaving 48 for the actual pointer. Will a userspace program ever get a kernelspace pointer, or is it safe to ...
Advice
1
vote
15
replies
322
views
Does p-- point to b in this code, or is the behavior undefined?
I am trying to understand whether the following C++ program has well-defined behavior.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a = 15, b = 10;
int *p = &a, *...
Score of 3
2 answers
231 views
How is a string of length > 1 able to fit inside a malloc(1) in C? [duplicate]
Consider this,
{
char* p = malloc(1);
strcpy(p, "Hello World!");
printf("%s", p);
}
This would print Hello World! .
But how, I expected this to fail, but it seems ...
Best practices
0
votes
19
replies
274
views
UB or not UB? (C11)
There is a piece of code, which definitely has UB:
free(s);
logsimple("fs body %p freed (g_free_body_cnt %d)", s, ++g_free_body_cnt);
logsimple() is just a macro-wrapper over fprintf(...
Score of 0
3 answers
210 views
Can a function reading (or writing) through a pointer parameter ever legitimately be marked noexcept?
Suppose I have a function which takes a pointer, either for reading from or for writing, e.g.:
int foo(int const* x) { return *x; }
Now, if x is an address into a readable part of memory - then this ...
Advice
2
votes
8
replies
220
views
Reference vs Pointers
There is a significant difference between a reference and a pointer. But I want to ask at the low level how are they different. Some people say that references are just pointers under the hood but and ...
Advice
0
votes
26
replies
307
views
how pointers are implemented internally
I am new to programming and learning about pointers in C , although it's easy but I want to know how pointers are implemented internally within systems because I want to be a system software so I am ...
Score of 0
2 answers
332 views
Why a reference to a pointer behaves differently from a reference to a non-pointer?
I'm trying to understand why a reference to a pointer behaves differently from a reference to a non-pointer.
The following program fails to compile with Clang:
int main()
{
int i = 42;
int *...
Score of 0
1 answer
206 views
misunderstanding of pointer-interconvertible definition in the standard
The definition of pointer-interconvertible (https://eel.is/c++draft/basic.compound#6) states that:
If two objects are pointer-interconvertible, then they have the same address, and it is possible to ...
Best practices
2
votes
4
replies
149
views
Declaring and using a pointer in assembly
Note I'm practicing asm after reading a book, sample code below is a skeleton function to read a file (it's incomplete and for practice only).
I'm allocating a 64-bit pointer file_buffer resq 1 in ...
Score of 1
1 answer
195 views
In Fortran, is there a guaranteed way to get a transposed array pointer?
UPDATE: See the answer I added, for a "somewhat acceptable" solution
For a 2-dimensional array, the expression transpose(x) is not acceptable in "variable context" so you can't ...
Score of 1
1 answer
142 views
Does implicit object creation necessarily happen at storage return location?
[intro.object] seems to say that implicit object creation, at least for operations that return a pointer, occurs at the returned location (https://eel.is/c++draft/intro.object#14 and https://eel.is/c++...
Advice
1
vote
7
replies
140
views
Coverage on casting Pointers to other data types
I have been studying C++ for a bit of time now. I am still a novice, but I continue to learn daily and practice and pickup new things.
One thing I haven't been seeing too much information on is ...
Advice
1
vote
1
replies
92
views
Should I set a non-python struct member to NULL or to PyNone?
My question might just be that I don't understand something in the Python API, but I have the following code for a node in a Linked List:
typedef struct Node {
PyObject* data;
struct Node* ...
Score of 1
2 answers
211 views
Pointer Value not being modified
Recently, for a small little project, I needed to write a barebones replacement for pwd.h, however, in implementing one function, something isn't working quite right. The code for win_pwd.h is:
#...