void형 변수 선언이 가능?

익명 사용자의 이미지

void* 이라고 해서 void형 포인터 선언은 가능하고, 잘 사용하는것으로 알고 있습니다.
근데 void를 통해서 지역변수 선언이 가능한가요? 가능하게하는 방법이나???

shint의 이미지


이 부분은 잘못된 내용 같네요. ㅇ_ㅇ;;

순수 가상 함수'로 비슷한 효과를 볼 수 있습니다.
http://blog.naver.com/cyber13510/220590497806
http://yoon90.tistory.com/8
 
#define ## 매크로.등을 사용해서. 비슷한 효과를 볼 수 있습니다.

void(0); 는 컴파일이 됩니다.

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

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

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

상수(const)의 정의가 궁금합니다... void 는 형 지정자(type specifier) 1순위 입니다.
https://kldp.org/node/144933

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

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

터보C 정복 책을 보면.
//403p 기억부류 지정자
//auto
//extern
//static
//register

//276p
//기본 연산자 primary operator ()[].->
//포인터 연산자 pointer operator * & ++ -- + - < <= > >= == != && || 등등 34가지
//전처리기 연산자 preprocessor operator # ## defined

//330p (void)형 함수를 앞에 붙이면. 리턴이 호출되지 않는다고 합니다. (viod)getch();
void 연산자'라고 하네요.

★ 1 패스 컴파일 - 터보C ★ 2 패스 컴파일 - 어셈블리 ★ 3 패스 컴파일 - MSVC
https://kldp.org/node/153220

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

오퍼레이트 연산자로 사용할 경우는 이렇습니다.
void operator
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/void

Functionality of void operator()()
http://stackoverflow.com/questions/11857150/functionality-of-void-operator

#include <stdio.h>
 
int main()
{
	void a;
	printf("%d\n", sizeof(a));
 
    return 0;
}
 
Severity	Code	Description	Project	File	Line	Suppression State
Error	C2182	'a': illegal use of type 'void'	ConsoleApplication1	c:\users\ieuser\desktop\consoleapplication1\consoleapplication1.cpp	12	

#include <stdio.h>
 
int main()
{
 
	void * b;
	printf("%d\n", sizeof(b));
    return 0;
}
 
x86 은 4바이트
x64 는 8바이트

근데. 리턴값으로 void 형은 가능하죠. ㅇ_ㅇ;;
void fn()
{
	return;
}

#include <stdio.h>
 
template <typename T>
class Template
{
public:
	T a, b;
	Template()
	{
		printf("constructor\n");
	}
};
 
 
void main()
{
	Template<void> test1;
}
 
Severity	Code	Description	Project	File	Line	Suppression State
Error	C2182	'a': illegal use of type 'void'	ConsoleApplication1	c:\users\ieuser\desktop\consoleapplication1\consoleapplication1.cpp	25	
 
http://changmyeong.tistory.com/9

#include <queue>
 
using namespace std;
 
int main()
{
	queue<void> a;
    return 0;
}
 
Severity	Code	Description	Project	File	Line	Suppression State
Error	C2182	'abstract declarator': illegal use of type 'void'	ConsoleApplication1	c : \program files(x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.24728\include\xmemory0	163
Error	C2182	'abstract declarator': illegal use of type 'void'	ConsoleApplication1	c : \program files(x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.24728\include\xmemory0	165
Error	C2182	'reference': illegal use of type 'void'	ConsoleApplication1	c : \program files(x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.24728\include\deque	978
Error	C2182	'const_reference': illegal use of type 'void'	ConsoleApplication1	c : \program files(x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.24728\include\deque	979
Error	C2070	'void': illegal sizeof operand	ConsoleApplication1	c : \program files(x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.24728\include\deque	986
Error	C2182	'_Val': illegal use of type 'void'	ConsoleApplication1	c : \program files(x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.24728\include\deque	1003

#include <iostream>
 
using namespace std;
 
template<bool B, class T = void>
struct enable_if {};
 
 
class Foo {
public:
	template <typename... Args, class T = void>
	Foo(Args... args) {
		cout << "Foo::Foo(args...)" << endl;
	}
};
 
 
int main()
{
 
	return 0;
}
이 방식은 컴파일이 가능하네요.

https://en.wikipedia.org/wiki/Variadic_template
https://en.wikipedia.org/wiki/Generic_programming
https://en.wikipedia.org/wiki/Partial_template_specialization

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

--------------------------
아래는 그냥 구경하다가 적습니다.
--------------------------

[C++11] Variadic Templates
http://cafe.naver.com/multism/5506

Ellipses 및 Variadic 템플릿
https://msdn.microsoft.com/ko-kr/library/dn439779.aspx

Variadic 매크로
https://msdn.microsoft.com/ko-kr/library/ms177415.aspx

Variadic function
http://rosettacode.org/wiki/Variadic_function

[C++11] Variadic template
http://bunhere.tistory.com/408

[C++11] 간단하게 Non-static data member initializers, Variadic templates, Initializer lists, Alias templates 맛보기
http://jacking.tistory.com/1192

[C++11] variadic template C++11 / Programming
http://blog.naver.com/kjpark79/220158467318

[C++11] Variadic Template 사용법 C++
http://milennium9.blog.me/20192447791

[c++ 11] std::tuple과 variadic template의 활용
http://blog.naver.com/cmw1728/220656689814

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

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

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

 의 이미지

단언컨대, 불가능합니다.

그러라고 만든 void가 아니기 때문이죠.

C11 std wrote:
The void type comprises an empty set of values; it is an incomplete object type that cannot be completed.

C++ 표준에서는 void 타입 표현식이 존재할 수 있음을 명시하고, 그 사용처를 한정지어 주는군요.

C++11 std wrote:
The void type has an empty set of values. The void type is an incomplete type that cannot be completed. It is used as the return type for functions that do not return a value. Any expression can be explicitly converted to type cv void (5.4). An expression of type void shall be used only as an expression statement (6.2), as an operand of a comma expression (5.18), as a second or third operand of ?: (5.16), as the operand of typeid or decltype, as the expression in a return statement (6.6.3) for a function with the return type void, or as the operand of an explicit conversion to type cv void.

생각 외로 여러 군데서 쓰일 수 있긴 하지만, 여전히 void 타입의 지역변수를 만든다던가 할 수는 없습니다.

익명 사용자의 이미지

C 에서 지역은 안되지만 전역으로는 선언할 수 있습니다.

shint의 이미지


//.c 파일
#include <stdio.h>
 
void aa;
 
int main()
{
	return 0;
}
 
Severity	Code	Description	Project	File	Line	Suppression State
Error (active)	E0070	incomplete type is not allowed	Project1	c:\Users\IEUser\Desktop\Project1\test.c	5	
Error	C2182	'aa': illegal use of type 'void'	Project1	c:\users\ieuser\desktop\project1\test.c	5	

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

매일 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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.