News for hackers. Stuff that matters.
Re:A convenient untruth: Array notation in C is a lie by itsuart on Thursday December 22, 2016 @01:25PM (#13239213)
It was always puzzling to me why people stick to

  char *foo 
instead of

  char* foo
foo is obviously a pointer to the char, not a char. It has different size and behavior.
Re:A convenient untruth: Array notation in C is a lie by gpderetta on Thursday December 22, 2016 @01:35PM (#13239288)
That's because [1]

  char* foo, bar;
doesn't mean what one would expect it to mean.

[1] as per Rule of Maximum Astonishment.

Re:A convenient untruth: Array notation in C is a lie by itsuart on Thursday December 22, 2016 @01:44PM (#13239350)
I find that

char* foo = NULL;

char bar = 0;

are preferable. Is there any reason one would want to smash N declarations into one?

Re:A convenient untruth: Array notation in C is a lie by gpderetta on Thursday December 22, 2016 @02:10PM (#13239528)
I prefer that as well, but because the other option is possible and sometimes used, a few prefer to put the star close to the name as to avoid mistakes.
Re:A convenient untruth: Array notation in C is a lie by cessor on Friday December 23, 2016 @10:22AM (#13245116)
I agree.

Simply put, it would sense to provide

    #define CharPointer char*
and then declare

    char c = 'a';
    CharCointer p = &c;
To me this became clear when I did some C# interop, where IntPtr is a common class, such as:

    [DllImport("user32.dll")]
    static extern IntPtr CallWindowProc(WndProcDelegate lpPrevWndFunc, IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
It's just an object oriented pointer interface. It looks different. I agree:

> It has different size and behavior.

Re:A convenient untruth: Array notation in C is a lie by wruza on Thursday December 22, 2016 @01:52PM (#13239416)
Otoh,

  *foo
is obviously a char. Do you put a space between dereference operator and its operand?
Re:A convenient untruth: Array notation in C is a lie by itsuart on Thursday December 22, 2016 @02:10PM (#13239525)
No, I don't. If foo is a (storage of) pointer to something, to get that something from memory I use dereference operator `* so

  *foo = 'a';
will write value of 'a' into memory at address that is in foo.

  type* foo;
is declaration and

  *foo
is dereferencing.