2010-02-16 16 views
8

क्या कोई अंतर है यदि मैं c89 बनाम c99 का उपयोग कर निम्न प्रोग्राम संकलित करता हूं? मुझे एक ही आउटपुट मिलता है। क्या वास्तव में दोनों के बीच एक अंतर है?सी 8 9 बनाम सी 99 जीसीसी कंपाइलर

#include <stdio.h> 

    int main() 
    { 
     // Print string to screen. 
     printf ("Hello World\n"); 
    } 

gcc -o helloworld -std=c99 helloworld.c 
vs 
gcc -o helloworld -std=c89 helloworld.c 
+5

"gcc -std = c89" और "gcc -std = c99" पूरी तरह से संबंधित मानकों के अनुरूप नहीं है। पूर्ण अनुरूपता के करीब आने के लिए "-pedantic" या "-pedantic-error" जोड़ें। –

उत्तर

6

सिद्धांत रूप में, एक अंतर होना चाहिए। टिप्पणी को डिमर्क करने के लिए "//" का उपयोग करना C89 का हिस्सा नहीं है, इसलिए यदि यह C89 नियमों को सही तरीके से लागू करता है, तो यह एक कंपाइलर त्रुटि उत्पन्न करेगा (-ansi -pedantic के साथ, यह ऐसा कर सकता है, लेकिन मुझे याद नहीं है ज़रूर)।

यह सामान्य चरित्र का विचार देता है हालांकि: यदि कोई प्रोग्राम C89 के रूप में संकलित होता है, तो यह आमतौर पर C99 के रूप में संकलित होगा, और बिल्कुल वही परिणाम देगा। सी 99 ज्यादातर आपको कुछ नई विशेषताएं खरीदता है जो सी 8 9 में मौजूद नहीं हैं, इसलिए आप (उदाहरण के लिए) वैरिएबल लम्बाई सरणी का उपयोग कर सकते हैं, जिन्हें सी 8 9 में अनुमति नहीं है।

आपको सभी मतभेदों को देखने के लिए पैडेंटिक नियम प्रवर्तन के लिए पूछना पड़ सकता है - सी 99 का मौजूदा अभ्यास को मानकीकृत करने का इरादा है, और कुछ मौजूदा अभ्यास जीसीसी एक्सटेंशन हैं, जिनमें से कुछ डिफ़ॉल्ट रूप से सक्षम हैं।

+2

+1, अच्छी पकड़; '//' टिप्पणियां सी 99 मूल्य लेने का एकमात्र हिस्सा हो सकती हैं। '-ansi -pedantic' एक त्रुटि के साथ आता है: 'main.c: 5: त्रुटि:'/'टोकन से पहले अपेक्षित अभिव्यक्ति' –

+1

मुझे नहीं लगता कि' // 'टिप्पणियां और अधिक उपयोगी कैसे हैं, यह केवल दो है कम अक्षर ... यह कहने जैसा है कि सी को '-' के बजाय संरचनाओं के लिए पॉइंटर्स के सदस्यों तक पहुंचने के लिए '.' का उपयोग करना चाहिए क्योंकि यह टाइपिंग बचाता है। –

+0

@ जोएडी '// 'टिप्पणियां केवल एक रेखा को पकड़ती हैं, जिसका अर्थ है कि वे अनजाने में टिप्पणियों के किसी अन्य सेट द्वारा कब्जा कर सकते हैं या समस्याओं का कारण बन सकते हैं। इसके अलावा, '.' के बारे में आपका तर्क मूर्खतापूर्ण है; मूल रूप से एक ही ऑपरेशन के लिए एक ही ऑपरेटर का उपयोग करना शायद एक अच्छा विचार है। – Alice

1

इस मंच http://www.velocityreviews.com/forums/t287495-p2-iso-c89-and-iso-c99.html पर मैंने पाया इस:

सारांश: 99 मानकीकृत है, नए कीवर्ड नई सरणी सामान, जटिल संख्याओं, पुस्तकालय कार्यों और इस तरह है। अधिक कंपाइलर्स सी 8 9 पूर्ण हैं क्योंकि इन्हें उन्हें बनाने के लिए इस बार सब कुछ हुआ है।

A) ANSI X3.159-1989. This is the original 1989 C standard, dated December 1989, with Rationale. The main body of the language is described in section 3, and the "C library" -- stdio, functions, and so on -- in section 4.

B) ISO 9899:1990. This is the original ISO C standard. "ANSI" is the American National Standards Institute, so the international crowd have to have their own standards with their own, different, numbering system. They simply adopted ANSI's 1989 standard, removed the Rationale, and renumbered the sections (calling them "clauses" instead). With very few exceptions you can just add three, so that most of the language is described in section -- er, "clause" -- 6, and the "C library" part in section 7.

C) ISO 9899:1999. This is the newfangled "C99" standard, with its Variable Length Arrays, Flexible Array Members, new keywords like "restrict" and "_Bool", new semantics for the "static" keyword, new syntax to create anonymous aggregates, new complex-number types, hundreds of new library functions, and so on.

The new ISO standard was immediately "back-adopted" by ANSI. I have not seen any official "ANSI-sanctioned" claim about this, but given the usual numbering systems, I would expect this to be ANSI Standard number X3.159-1999. (The numbering system is pretty obvious: a standard, once it comes out, gets a number -- X. for ANSI, or just a number for ISO -- and a suffix indicating year of publication. An update to an existing standard reuses the number, with the new year.)

Although X3.159-1989 and 9899:1990 have different years and section numbering, they are effectively identical, so "C89" and "C90" really refer to the same language. Hence you can say either "C89" or "C90" and mean the same thing, even to those aware of all the subtleties.

There were also several small revisions to the original 1990 ISO standard: "Normative Addendum 1", and two "Technical Corrigenda" (numbered; giving Technical Corrigendum 1 and TC2). The two TCs are considered to be "bug fixes" for glitches in the wording of the standard, while NA1 is an actual "change". In practice, the TCs do not really affect users, while NA1 adds a whole slew of functions that people can use, so NA1 really is more significant. NA1 came out in 1994, so one might refer to "ISO 9899:1990 as modified by NA1" as "C94". I have seen it called "C95", too.

28
  • // टिप्पणी C89 का एक हिस्सा
  • C89 में किसी भी मूल्य लौटने के बिना main() के गिरने C99 में return 0; के बराबर है, लेकिन नहीं तो नहीं हैं, लेकिन C99 में ठीक कर रहे हैं। N1256 (पीडीएफ), 5.1.2.2.3p1 से:

    If the return type of the main function is a type compatible with int , a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument; reaching the } that terminates the main function returns a value of 0.

C89 में तो अपने कोड अपरिभाषित है व्यवहार, और C99 में अच्छी तरह से परिभाषित व्यवहार।

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^