#include "stdafx.h" 를 하면 stdafx.cpp 파일도 자동으로 include 되는건가요??

cleitia의 이미지

메인코드에서 #include "stdafx.h"만 해주면 stdafx.cpp 에 있는 코드들도 인식을 하는 것 같아서 이런 질문을 남겨봅니다.

우선 각 파일의 내부 코드는 아래와 같습니다.

  1. // stdafx.h : include file for standard system include files,
  2. // or project specific include files that are used frequently, but
  3. // are changed infrequently
  4. //
  5.  
  6. #pragma once
  7.  
  8. #include "targetver.h"
  9.  
  10. #include <stdio.h>
  11. #include <tchar.h>
  12.  
  13.  
  14.  
  15. // TODO: reference additional headers your program requires here

stdafx.cpp

  1. // stdafx.cpp : source file that includes just the standard includes
  2. // TestPCL.pch will be the pre-compiled header
  3. // stdafx.obj will contain the pre-compiled type information
  4.  
  5. #include "stdafx.h"
  6.  
  7. // TODO: reference any additional headers you need in STDAFX.H
  8. // and not in this file
  9.  
  10.  
  11. #ifdef _DEBUG
  12. #pragma comment(lib, "pcl_apps_debug.lib")
  13. #pragma comment(lib, "pcl_common_debug.lib")
  14. #pragma comment(lib, "pcl_features_debug.lib")
  15. #pragma comment(lib, "pcl_filters_debug.lib")
  16. #pragma comment(lib, "pcl_io_debug.lib")
  17. #pragma comment(lib, "pcl_io_ply_debug.lib")
  18. #pragma comment(lib, "pcl_kdtree_debug.lib")
  19. #pragma comment(lib, "pcl_keypoints_debug.lib")
  20. #pragma comment(lib, "pcl_octree_debug.lib")
  21. #pragma comment(lib, "pcl_registration_debug.lib")
  22. #pragma comment(lib, "pcl_sample_consensus_debug.lib")
  23. #pragma comment(lib, "pcl_search_debug.lib")
  24. #pragma comment(lib, "pcl_segmentation_debug.lib")
  25. #pragma comment(lib, "pcl_surface_debug.lib")
  26. #pragma comment(lib, "pcl_tracking_debug.lib")
  27. #pragma comment(lib, "pcl_visualization_debug.lib")
  28.  
  29. #else
  30.  
  31. #pragma comment(lib, "pcl_apps_release.lib")
  32. #pragma comment(lib, "pcl_common_release.lib")
  33. #pragma comment(lib, "pcl_features_release.lib")
  34. #pragma comment(lib, "pcl_filters_release.lib")
  35. #pragma comment(lib, "pcl_io_release.lib")
  36. #pragma comment(lib, "pcl_io_ply_release.lib")
  37. #pragma comment(lib, "pcl_kdtree_release.lib")
  38. #pragma comment(lib, "pcl_keypoints_release.lib")
  39. #pragma comment(lib, "pcl_octree_release.lib")
  40. #pragma comment(lib, "pcl_registration_release.lib")
  41. #pragma comment(lib, "pcl_sample_consensus_release.lib")
  42. #pragma comment(lib, "pcl_search_release.lib")
  43. #pragma comment(lib, "pcl_segmentation_release.lib")
  44. #pragma comment(lib, "pcl_surface_release.lib")
  45. #pragma comment(lib, "pcl_tracking_release.lib")
  46. #pragma comment(lib, "pcl_visualization_release.lib")
  47. #endif

// TestPCL.cpp : Defines the entry point for the console application. //

#include "stdafx.h"

#include
#include
#include

using namespace std;
using namespace pcl;
using namespace io;

int _tmain(int argc, _TCHAR* argv[])
{
PointCloud cloud;

// 5x1 짜리 xyz point cloud data buffer를 할당한다.

cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.points.resize (cloud.width * cloud.height);

//랜덤 값을 넣어준다.

for (size_t i = 0; i < cloud.points.size (); ++i)
{
cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
}

// 값을 저장한다.

savePCDFileASCII ("test_pcd.pcd", cloud);

cerr << "Hello World" << endl;
cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << endl;

// 값을 터미널에 출력한다

for (size_t i = 0; i < cloud.points.size (); ++i)
cerr << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << endl;

return 0;
}

shint의 이미지

제 생각에
#include 는 코드위에 소스를 그냥 넣은 겁니다.

//stdafx.cpp
int test = 2;
int fn()
{
    return 10;
}
 
//stdafx.h
extern int test;
int fn();
 
//main.cpp
 
void fn_test()        --- 이 코드는 컴파일 에러 납니다. test가 없습니다.
{
    return test;
}
 
#include "stdafx.h"
 
void fn_test()        --- 이 코드는 컴파일이 정상적으로 됩니다.
{
    return test;
}

그리고. 컴파일 될 경우.
stdafx.o 와
main.o 파일이 생성 됩니다.

main은 stdafx.h의 헤더를 참조한 목적 파일을 생성하고.
stdafx 역시 stdafx.h의 헤더를 참조한 목적 파일을 생성하게 됩니다.

//
void test();

이것은 main() 위에 함수를 두는것과 마찬가지 형식이 됩니다.

void test()
{
}

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

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