헤더와 연결
Coddy의 GDScript 개발자를 위한 C 코스 레슨. 48개 중 18번째.
GDScript 파일은 클래스입니다. preload는 이를 리소스로 불러오고 class_name은 전역으로 등록하며, 스크립트에 텍스트가 붙여 넣어지지 않습니다. C의 #include는 컴파일 전에 텍스트를 포함합니다. 선언과 공유 타입은 가드가 적용된 헤더에 넣고, 정의는 소스 파일에 넣은 다음 각 소스를 한 번씩 컴파일하세요. GDScript에서는 이름 앞에 밑줄을 붙이는 관례로만 비공개 멤버를 표시하지만, 정적 파일 범위 C 헬퍼는 실제로 해당 번역 단위에서만 사용할 수 있습니다.
GDScript
extends Node
func total(price: int, count: int) -> int:
return price * count
func _ready():
print(total(3, 4))
C17
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include <limits.h>
#include <errno.h>
static int total(int price,int count){return price*count;}
int main(void) {
printf("%d\n",total(3,4));
return 0;
}
포팅 규칙
가드가 적용된 헤더를 통해 함수 선언을 공유하고 소스 정의를 링크하세요.
챌린지
쉬움lesson.h에 선언된 public 함수 subtotal(price,count)를 구현하세요. 필요하다면 lesson.c에서 private static multiply helper를 사용하세요. price와 count를 곱한 값을 반환하세요. 채점기는 helper의 스타일이 아니라 동작을 확인합니다.
잠금 해제된 소스 파일과 헤더 파일을 수정하세요. 이를 직접 호출하는, 잠긴 상태로 표시된 main.c와 선언된 public API의 호환성을 유지하세요. 다른 main을 추가하지 마세요. 작업에 명시적으로 범위 검사가 포함되어 있지 않는 한, 모든 숫자 작업용 테스트 데이터는 오버플로가 발생하지 않을 만큼 작습니다. 지정된 출력만 출력하세요. 드라이버가 제공된 경우 입력 파싱과 출력을 처리합니다.
직접 해보기
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdbool.h>
#include <limits.h>
#include <errno.h>
#include "lesson.h"
int main(void){int a=0,b=0;if(scanf("%d%d",&a,&b)!=2)return 1;printf("%d\n",subtotal(a,b));return 0;}
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
GDScript 개발자를 위한 C의 모든 레슨
직접 연습해 보세요: 온라인 C 컴파일러