winsock send 함수의 파라미터 질문입니다.

love_cat2의 이미지

 int send(SOCKET s, const char* buf, int len, int flags);

winsock의 send 함수에 두번째 파라미터를 보시면, const char* 형태로 데이터 버퍼의 주소를 요구하는데요..

여기서 궁금한 점이 있는데요

1. buf가 굳이 char* 형인 이유가 뭔가요?
제 생각엔 1바이트 * len만큼 딱 떨어지게 읽어들이기 위해 그런것이 아닐까 싶은데...

2. 1바이트씩 역참조가 가능해서가 맞다면 그냥 void*를 써도 될 거 같은데,
옛날엔 void*가 표준이 아니였기에 char*를 썼다는 말을 본 것 같습니다. 이 말이 맞는 말인가요?

shint의 이미지

- 1 바이트 =/= 8 비트 (6비트도 사용한다고 합니다.)
1 바이트가. 반드시 8 비트는 아니라는 말이죠.

- CPU 에 따라서. 바이트 순서가 다른.
빅 인디언과 리틀 인디언이 있습니다.

- call by reference 를 하면. 데이터 복제 없이. 주소의 값을 사용합니다.
- ★ 1 패스 컴파일 - 터보C ★ 2 패스 컴파일 - 어셈블리 ★ 3 패스 컴파일 - MSVC
- (void*)p 는 rvalue(임시변수)라고 하네요.

- 대부분의? 변수(char int void). 포인터 주소의 크기는.
32비트에서는 4 바이트. 64비트에서는 8 바이트를 사용합니다.

잘하면. 1바이트. 1비트에 포인터 주소를 만들어서 사용할 수 도 있을겁니다.?? ㅇ_ㅇ???

- const는 변경자(Modifier)이고. constant는 상수 입니다.

void 는 형 지정자에 해당합니다.
const 는 변경자에 해당합니다.

//
변경자 데이터형 상수값
const int 10

터보C 정복 책을 보면.

//--------------------------------------------
163p
지정자 (specifier)와 변경자 (modifier)
형지정자(type specifier)의 종류 12가지
1. char, int, float, double, void
2. short, long, signed, unsigned
3. struct specifier, union specifier
4. enum specifier
5. typedef name

//--------------------------------------------
164p에 기억부류지정자와 변경자는 총 17개 입니다.
기억부류 지정자(storage class specifier)
typedef, extern, static, register, auto

const, volatile
포인터 변경자(pointer modifier)
near, far, huge, _cs, _ds, _es, _ss

함수 변경자(function modifier)
interrupt

특수한 목적에 쓰이는 변경자
cdecl, pascal

//--------------------------------------------
731p ~ 733p

터보 파스칼에는 형지정 상수(typed constant) 라는 것이 있다.
const가 바로 그 파스칼의 형지정 상수와 유사한 새로운 데이터형을 만들어주는 변경자(modifier)이다.

const float pi = 3.141592;
*(float*)(&pi) = 20.0;

변환자를 사용하면. 값을 바꿀 수 있습니다.
- data segment 로 메모리 주소를 확인하실 수 있습니다.

//--------------------------------------------
- void
함수 반환 형식으로 사용된 경우 void 키워드는 함수가 값을 반환하지 않도록 지정합니다.
함수의 매개 변수 목록에 사용된 경우 void는 함수가 매개 변수를 사용하지 않도록 지정합니다.
포인터 선언에 사용된 경우 void는 포인터를 "범용"으로 지정합니다.

포인터 형식이 void *이면 포인터가 const 또는 volatile 키워드로 선언되지 않은 모든 변수를 가리킬 수 있습니다.
void 포인터는 다른 형식으로 캐스팅되지 않은 경우 역참조할 수 없습니다.
void 포인터를 다른 형식의 데이터 포인터로 변환할 수 있습니다.

void 포인터는 함수를 가리킬 수 있지만 C++의 클래스 멤버는 가리킬 수 없습니다.
void 형식의 변수는 선언할 수 없습니다.

//--------------------------------------------
//
send function
https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-send

The send function sends data on a connected socket.

int WSAAPI send(
SOCKET s,
const char *buf,
int len,
int flags
);
A pointer to a buffer containing the data to be transmitted.

When to use const void*?
https://stackoverflow.com/questions/34842224/when-to-use-const-void

Pointers: Pass By Address, Pointers and Arrays
https://www.cs.fsu.edu/~myers/c++/notes/pointers2.html

const Value
https://slideplayer.com/slide/9761273/

07 C | How to convert void pointer into char int float double
https://www.youtube.com/watch?v=eIL3oMmn1OM

int main() vs void main() vs int main(void) in C & C++
https://www.codesdope.com/blog/article/int-main-vs-void-main-vs-int-mainvoid-in-c-c/

void* vs. char* pointer arithmetic
https://stackoverflow.com/questions/10058234/void-vs-char-pointer-arithmetic

It's a slip-up. Arithmetic on void * is not defined by the standard, but some compilers offer it as an extension, behaving the same as char * for arithmetic. The second is formally not valid C, but slipped through presumably out of (bad) habit.
실수예요. 보이드의 산술 *는 표준에 의해 정의되지 않지만 일부 컴파일러는 산술의 경우 char *와 동일하게 동작하는 확장자로 이를 제공합니다. 두 번째 것은 공식적으로 유효하지 않은 C이지만, 아마도 습관적으로 통과했을 것이다.

void * vs char *
https://bytes.com/topic/c/answers/618725-void-vs-char

http://codepad.org/bAfGbvtX
printf("%d\n", ((struct s*)p)->a);

void * vs char * vs uint8_t * #5497
https://github.com/RIOT-OS/RIOT/issues/5497

difference between void* and char* as generic pointer?
https://groups.google.com/forum/#!msg/comp.lang.c/kz6ORGo6GD8/eTAjTp1_AxsJ

The void pointer is the correct generic pointer for C. The char pointer was
used before ISO/ANSI standards (void was new with the standard).
무효 포인터는 C에 대한 올바른 일반 포인터입니다. 문자 포인터는 ISO/ANSI 표준 이전에 사용되었습니다(보드는 표준과 함께 새 항목임).

Computer Programming: What is the Difference between void pointer and integer pointer?
https://www.quora.com/Computer-Programming-What-is-the-Difference-between-void-pointer-and-integer-pointer

//
리틀엔디안(Little-endian)과 빅엔디안(Big-endian)이해하기
http://www.packetinside.com/2010/10/리틀엔디안little-endian과-빅엔디안big-endian이해하기.html

빅엔디안과 리틀엔디안 개념
https://firejune.com/1790/빅엔디안과+리틀엔디안+개념

Little Endian & Big Endian
https://www.bogotobogo.com/Embedded/Little_endian_big_endian_htons_htonl.php

Little Endian vs Big Endian
https://thebittheories.com/little-endian-vs-big-endian-b4046c63e1f2

エンディアンが異なるマイコンでの移植テクニック
https://www.iar.com/jp/support/2/articles/migration-techniques-for-different-endianness/

Big-Endian vs Little-Endian: How Do You Remember Which is Which?
https://techiesimon.com/2014/12/10/bigendianlittleendian/

//
[질문] const 포인터가 헷갈립니다.
https://kldp.org/node/48414

c++ const 객체 참조자와 const static 멤버변수
https://kldp.org/node/154710

C++에서 클래스의 멤버 변수로 const int가 있다면, 이는 정수 상수가 아닌가요?
https://kldp.org/node/135000

C언어에서 (void *)0, (const void *)0, (void * const)0 세가지의 차이점
https://kldp.org/node/75306

(void *)0과 (void * const)0 전체가 널 포인터 상수
int (*pf1)() = (void *)0;
int (*pf2)() = (void * const)0;
int (*pf3)() = (const void *)0; /*wrong*/

> (const void*)0;
> (int *)0;

[완료] C++ 클래스에서 const char형 포인터를 초기화 해주고 싶습니다
https://kldp.org/node/92809

void*&캐스팅 질문과 const지정자 질문
https://kldp.org/node/140224

(void*)p 는 rvalue(임시변수)입니다.
rvalue를 reference로 받는 것은 const reference(이경우에는 void *const &)나 C++11에서 추가된 rvalue-reference만 가능합니다.

char c;
char * cp = & c;
void * const & crvp= cp;

std::cout << "cp =" << (void *)cp << std::endl;
std::cout << "crvp=" << crvp << std::endl;
++cp;
std::cout << "cp =" << (void *)cp << std::endl; // cp는 변함
std::cout << "crvp=" << crvp << std::endl;
// crvp는 cp를 가리키지 않으므로 그 값이 변하지 않음

static 기억부류를 갖는 대상체 초기화 질문입니다.
https://kldp.org/node/157401

7) More latitude is permitted for constant expressions in initializers. Such a constant expression shall be, or evaluate to, one of the following:
? an arithmetic constant expression,
? a null pointer constant,
? an address constant, or
? an address constant for an object type plus or minus an integer constant expression.

Initializer element is not constant in C [duplicate]
https://stackoverflow.com/questions/12750796/initializer-element-is-not-constant-in-c
C 프로그래밍 언어에서 정적 저장 기간이 있는 개체는 상수 식(또는 상수 식을 포함하는 Aggregate)으로 초기화해야 합니다.
endX에 정적 저장 기간이 있는 경우 해당 initizer(c+a)는 상수 식이 아닙니다(즉, 변환 단계 중에는 식을 계산할 수 없습니다).

C언어 주로 constant와 관련된 질문입니다.
https://kldp.org/node/155779

[c언어] 구조체 안에 상수 사용이 안됩니다.
https://kldp.org/node/159382

- const 는 변경자이고. constant 는 상수'라고 합니다.
void(0); 는 컴파일이 됩니다.

변경자 데이터형 상수값
const int 10

const는 변경자(Modifier)이고. constant는 상수 입니다.

이 에러 -_-;; reduce to an integer constant
https://kldp.org/node/22286

void형 변수 선언이 가능?
https://kldp.org/node/156758

순수 가상 함수'로 비슷한 효과를 볼 수 있습니다.

void (C++)
https://msdn.microsoft.com/ko-kr/library/fxky5d0w.aspx

함수 반환 형식으로 사용된 경우 void 키워드는 함수가 값을 반환하지 않도록 지정합니다.
함수의 매개 변수 목록에 사용된 경우 void는 함수가 매개 변수를 사용하지 않도록 지정합니다.
포인터 선언에 사용된 경우 void는 포인터를 "범용"으로 지정합니다.

포인터 형식이 void *이면 포인터가 const 또는 volatile 키워드로 선언되지 않은 모든 변수를 가리킬 수 있습니다.
void 포인터는 다른 형식으로 캐스팅되지 않은 경우 역참조할 수 없습니다.
void 포인터를 다른 형식의 데이터 포인터로 변환할 수 있습니다.

void 포인터는 함수를 가리킬 수 있지만 C++의 클래스 멤버는 가리킬 수 없습니다.
void 형식의 변수는 선언할 수 없습니다.

★ 1 패스 컴파일 - 터보C ★ 2 패스 컴파일 - 어셈블리 ★ 3 패스 컴파일 - MSVC

Void type
https://en.wikipedia.org/wiki/Void_type

Void 유형은 C 및 Algol68에서 파생 된 여러 프로그래밍 언어로 정상적으로 리턴되지만 결과 값을 호출자에게 제공하지 않는 함수의 결과 유형입니다.
일반적으로 이러한 함수는 작업을 수행하거나 출력 매개 변수에 쓰는 것과 같은 부작용이 필요합니다.
이러한 상황에서 void 형의 사용은 Visual Basic에서 서브 루틴을 정의하는 파스칼 및 구문 구문의 프로 시저와 유사합니다.
또한 함수형 프로그래밍 언어 및 유형 이론에서 사용되는 단위 유형과 유사합니다. 비교를 위해 프로그래밍 언어에서 단위 유형 #을 참조하십시오.

C와 C ++은 void 형 (void *로 명시된)에 대한 포인터도 지원하지만, 이것은 비 관련 개념이다.
이 유형의 변수는 지정되지 않은 유형의 데이터에 대한 포인터이므로이 문맥 (다른 문맥은 아님)에서 void *는 대략 범용 또는 맨 위 유형과 유사하게 작동합니다.
프로그램은 void 포인터에 대한 포인터 (함수 포인터 제외)를 모든 유형의 데이터로 변환하고 정보를 잃지 않고 원래 형식으로 되돌릴 수 있습니다.
이 포인터는 다형 함수에 유용합니다. C 언어 표준은 다른 포인터 유형의 크기가 동일하다는 것을 보장하지 않습니다.

상수(const)의 정의가 궁금합니다...
https://kldp.org/node/144933

기억부류 지정자(storage class specifier)

과연 C++이 C언어보다 쉬운가?
https://kldp.org/node/153220

variadic template parameter로 인한 모호한 호출 c/c++
https://blog.naver.com/cmw1728/220724096915

[C++] 클래스 상속과 오버라이딩, 순수 가상함수
http://yoon90.tistory.com/8

[C++] 순수 가상 함수 + 상속 + 소멸자 예제 소스 코드
https://blog.naver.com/cyber13510/220590497806

//
데이터 세그먼트 Data Segment + 선언부 '만으로 프로그램 완성 | VC++ 일반
http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=51&MAEULNO=20&no=8885&page=1

Data Segment를 모두 소모하면 어떠한 시그널이 날아오나요?
https://kldp.org/node/68165

데이터 영역과 .bss 영역의 차이
https://kldp.org/node/122255

선배님들 Section 과 Segment 의 차이점에 대해서 질문있습니다.
https://kldp.org/node/154707

OS가 메모리를 관리할 때 비슷한 특성을 가진 덩어리 단위로 관리한다는 거고, 이걸 학문적인 용어로 Segment라고 합니다

실행 파일을 이루는 데이터는 가급적이면 "그 내용을 메모리에 펼쳐놓기 편하게" 구성하는 것이 효율적이겠죠?
그래서 실행 파일들의 구조(윈도우의 PE, 리눅스의 ELF 등)를 보면 마찬가지로 비슷한 특성, 기능을 가지는 데이터들을 한데 모아서,
그 단위대로 읽어서 메모리에 올려놓을 수 있게 디자인 되어 있습니다. 이 단위를 Section이라고 하고요.

힙과 스택의 개념은?
https://kldp.org/node/199

Intel linux Privilege Level check 관련 질문입니다.
https://kldp.org/node/37180

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.