[완료] Mini Shell 구현에 한가지 문제점이 생겼습니다;;

hhkwoong의 이미지

첨부파일과 같은 소스로 컴파일을 하는데 Pipe 함수를 생성하는것에 문제가 있네요;;
에러 코드는 다음과 같습니다. (Solaris GCC에서 컴파일 하였습니다.)

================================================================================
travis[/export/home/sccv/LAB/Linux] # gcc -o shell shell.c
shell.c: In function `Pipe':
shell.c:182: error: called object is not a function
================================================================================

답변 부탁드리겠습니다;; 감사합니다. 수고하세요~

File attachments: 
첨부파일 크기
Plain text icon shell.txt5.4 KB
lifthrasiir의 이미지

g++ 확장 같은 걸 쓰지 않는 한 C에서 함수 안에는 다른 함수를 넣을 수 없습니다. 중괄호 위치를 잘 바꿔 보세요. (덤 힌트: pipe는 main 함수에서 무엇으로 정의되어 있을까요?)

일반인의 이미지

덕분에 저도 문제를 해결했네요 .

단순한 문제였다니 다행

hhkwoong의 이미지

말씀하신것 처럼 source 를 cpp파일로 바꾼후에 g++ 로 컴파일 하였더니 또다른 에러에 직면하였습니다;;
==============================================================================================
shell.cpp: In function `int main(int, char**)':
shell.cpp:128: error: a function-definition is not allowed here before '{' token
shell.cpp:159: error: a function-definition is not allowed here before '{' token
shell.cpp:180: error: a function-definition is not allowed here before '{' token
shell.cpp:211: error: a function-definition is not allowed here before '{' token
==============================================================================================
이번엔 이런 에러가 떨어지네요;;
정말 난감합니다...도통 소스는 문제가 없는것 같은데ㅜㅜ

bootmeta의 이미지

다른 함수 안에서 함수 정의부를 넣지 않는 것이 좋습니다.
제가 알기로 pascal과 달리 c 표준의 경우 함수 내에서 함수 정의는 허용하지 않습니다.

gcc에선 만일 다른 함수 내에서 함수 정의를 한다면 함수 정의는 함수 호출 전에 위치해야 하는 것으로 보입니다. 아마 함수 원형 선언만으로 해결되지 않는 것으로 보이는 군요.

#include<stdio.h>
 
void in_fn();
 
int main()
{
   in_fn();      /* 함수 호출 - 함수 정의 아래에서 호출하면 정상적으로 실행 */
 
   void in_fn(); /* 함수 정의 */
   {
      printf("in_fn\n");
   }
 
   printf("main\n");
 
   return 0;
}

$> gcc -Wall testin.c
 
undefined reference to `in_fn'

댓글 달기

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