줄바꾸기 문의.

joony77의 이미지

안녕하세요?
이제 막? 시작한사람이라 잘몰라서 문의드립니다.

if (true)
pr_info("abcdefghijklmnopqr...."); // 이줄이 80자가 넘어가면,

if (true)
pr_info(
"abcdefghijklmnopqr....");

이런식으로 해야 되는지?
아님

if (true) {
pr_info(
"abcdefghijklmnopqr....");
}

줄이 바뀌었으니까 괄호를 해주어야 하는지?

gurugio의 이미지

("asdfasdfasdf"
"asdfasdfasdf"
"asdfasdf");

전 이렇게 씁니다.

addnull의 이미지

잘 알려진 Indent 스타일을 쓰시는게 좋습니다.
http://en.wikipedia.org/wiki/Indent_style

그리고 이런 소스 정렬 기능은 수작업으로 하는 것보다 IDE에서 "자동 정렬(auto indent, formatting)" 기능을 쓰시는게 좋습니다.

kid1402의 이미지

질문하신 내용에만 답변을 드리자면

if() 문 뒤에 {}로 구분해주지 않으면 단 하나의 구문만이 올 수 있습니다.
위에서 pr_info();라는 함수가 곧 하나의 구문에 카운트 되므로 pr_info()함수에게 넘겨주는 파라미터 값이 길어서 엔터로 구분하는건 전혀 상관없다는 뜻이지요..

그러니까

if(true)
    pr_info("asdf
                 sdf
                 sdfsfaq");

로 적으셔도 컴파일러는 알아서 중괄호 친것과 같게 받아들인다는 거죠.

다만 저렇게 하시는경우 나중에 if문안에 다른 함수를 추가해야한다거나 하는 확장 상황에서 에러가 날 가능성이 있죠.
그래서 보통은 중괄호로 감싸는걸 추천합니다.

planetarium의 이미지

pr_info("asdf
                 sdf
                 sdfsfaq");


pr_info("asdfsdfsdfsfaq");

는 물론이고
pr_info("asdf sdf sdfsfaq");

와도 다릅니다.

생각해보면 당연한거지만
C언어에서 whitespace를 자유롭게 사용하는 것은
큰따옴표로 감싸진 문자열에는 적용되지 않는 규칙입니다.

물론 말씀하신 내용을 의미 그대로만 해석하면 틀린게 없습니다만
오해의 소지도 많고, 질문자가 원하는건 그런 내용이 아니니까요.

결론적으로
80자 coloumn을 지키면서 긴 문자열을 표현하고 싶다면
gurugio님의 댓글이 추천할만한 방법입니다.

댓글 달기

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