A Matter of Style
When declaring pointer and reference variables, some C++ programmers use a unique
coding style that associates the * or the & with the type name and not the variable. For
example, here are two functionally equivalent declarations:

int& p; // & associated with type
int &p; // & associated with variable

Associating the * or & with the type name reflects the desire of some programmers
for C++ to contain a separate pointer type. However, the trouble with associating the &
or * with the type name rather than the variable is that, according to the formal C++
syntax, neither the & nor the * is distributive over a list of variables. Thus, misleading
declarations are easily created. For example, the following declaration creates one, not
two, integer pointers.

int* a, b;

Here, b is declared as an integer (not an integer pointer) because, as specified by the
C++ syntax, when used in a declaration, the * (or &) is linked to the individual variable
that it precedes, not to the type that it follows. The trouble with this declaration is that
the visual message suggests that both a and b are pointer types, even though, in fact,
only a is a pointer. This visual confusion not only misleads novice C++ programmers,
but occasionally old pros, too.

It is important to understand that, as far as the C++ compiler is concerned, it
doesn’t matter whether you write int *p or int* p. Thus, if you prefer to associate the *
or & with the type rather than the variable, feel free to do so.


typedef 문을 ,와 함께 쓰는 경우가 종종 있다
생각해 보면 의미는 당연한데 처음에는 좀 헷갈릴 수 있다

--------------------------------------------------
#include <iostream>

using namespace std;

typedef struct {
  int a;
  int b;
  int c;
} mytype, *pmytype;

int main()
{
  mytype var_a;
  pmytype ptr_a;

  ptr_a = &var_a;

  var_a.a = 10;
  var_a.b = 20;
  ptr_a->c = 30;

  cout << "values of var_a is " << ptr_a->a << " " 
       << ptr_a->b << " " << var_a.c << endl;

  return 0;
}



리눅스에서는.

    FILE *fp; 에서

    fp->_fileno 로 file desctiptor 를 뜻하는 integer  값을 얻을 수 있고

 

반면 윈도우에서는,

  FILE *fp; 에서

  fp->_file 을 사용해야 함


int main()
{

char *str1 = “1234567890″;
char str2[] = “1234567890”;

char *str3= “1234″;

memcpy(str1, str3, strlen(str3));    <—(1)

memcpy(str2, str3, strlen(str3));    <—(2)

return 0;

}

여기서 (2)는 기대한대로 동작하지만,

(1)은 segmentation fault 발생시킨다.

 


FILE *fp;

fp = fopen(“/tmp/daemon.out”, “wt”);

if (fp == NULL) {

    printf(“File Open Error\n”);

    return –1;

}

 

대략 위와 같은 맥락에서

fopen(“~/daemon.out”, “wt”) 이렇게 사용하니까

내가 실행하고 있는 user 의 home directory에 만들어 주는게 아니라

fp = NULL 이 return 한다.

 

그러면 my home directory에 만들려면

어떻게 해야 할까?

environment 에서 읽어와서 스트링 연결을 해야하겠구만…