| | |
complex declarations & other doubts
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2005
Posts: 15
Reputation:
Solved Threads: 0
1) Plz explain these complex declarations(from K&R).--
The one line explanations which r given as comment were given in K&R but i couldnt understand them.
Do u know some links to tutorial of these kind of complex declarations?
2) Is there any special reason of- Why most C compilers include most of the header files implicitly, but in C++ we have to include them explicitly?
3) Can a global variable in C be declared anywhere in the program(outside all functions)?
ex-
int i;
main()
{
/*body*/
}
int j;
test()
{
/*body*/
}
int k;
Is this code valid according to C standards?
4) Is the value of NULL=0 according to C/C++ standard?
C++ Syntax (Toggle Plain Text)
char(* (*f())[]) () // f : a function returning pointer to array[] of pointer to function returning char. char(* (*x[3])()) [5] // x: array[3] of pointer to function returning pointer to array[3] of char.
Do u know some links to tutorial of these kind of complex declarations?
2) Is there any special reason of- Why most C compilers include most of the header files implicitly, but in C++ we have to include them explicitly?
3) Can a global variable in C be declared anywhere in the program(outside all functions)?
ex-
int i;
main()
{
/*body*/
}
int j;
test()
{
/*body*/
}
int k;
Is this code valid according to C standards?
4) Is the value of NULL=0 according to C/C++ standard?
•
•
•
•
Originally Posted by akshayabc
2) Is there any special reason of- Why most C compilers include most of the header files implicitly, but in C++ we have to include them explicitly?
•
•
•
•
Originally Posted by akshayabc
3) Can a global variable in C be declared anywhere in the program(outside all functions)?
ex-
int i;
main()
{
/*body*/
}
int j;
test()
{
/*body*/
}
int k;
Is this code valid according to C standards?
•
•
•
•
Originally Posted by akshayabc
4) Is the value of NULL=0 according to C/C++ standard?
1)
Just work your self out from the middle, if they are given in k&r they describe them in k&r ?
returning
returning
(Ok, this was a pain in the ass, but I doubt youll ever see anything like that in real life)
2)
C does not include default headers, instead C has implicit function declarations...
if the compiler sees a function call it has not seen before it assumes it is declared as a function
Just work your self out from the middle, if they are given in k&r they describe them in k&r ?
char(* (*f())[]) ()*f() => f is function pointer taking zero argumentsreturning
(* ... [])() => returning array of pointer to functionsreturning
char ... => returning char...(Ok, this was a pain in the ass, but I doubt youll ever see anything like that in real life)
2)
C does not include default headers, instead C has implicit function declarations...
if the compiler sees a function call it has not seen before it assumes it is declared as a function
int function_name( function_args ) (ie it returns an int) leaving the linker to fail if there really is no such function. I think you can get a warning for this with -Wall or some other flag but I'm not sure. (Or compile it with a c++ compiler). /pern.*/i
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. Albert Einstein
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. Albert Einstein
>2) Is there any special reason of- Why most C compilers include
>most of the header files implicitly, but in C++ we have to include them explicitly?
A correct and portable program must include the headers it uses explicitly or otherwise provide a compatible declaration for everything it uses from that header. However, you may have just gotten lucky because traditionally, if a declaration isn't specified in C, a default declaration is used. That default declaration is often compatible enough to avoid irritating the compiler and then the linker gives you the correct function. A lot of people consider this to be a misfeature (it was removed in the latest standard) and if you rely on it, you're treading on very thin ice. This is one of those areas where if you choose to abuse it, you'd better know damn well how it works in all cases.
>most of the header files implicitly, but in C++ we have to include them explicitly?
A correct and portable program must include the headers it uses explicitly or otherwise provide a compatible declaration for everything it uses from that header. However, you may have just gotten lucky because traditionally, if a declaration isn't specified in C, a default declaration is used. That default declaration is often compatible enough to avoid irritating the compiler and then the linker gives you the correct function. A lot of people consider this to be a misfeature (it was removed in the latest standard) and if you rely on it, you're treading on very thin ice. This is one of those areas where if you choose to abuse it, you'd better know damn well how it works in all cases.
New members chased away this month: 3
![]() |
Similar Threads
- Hardware Interrupts & 100% CPU usage (Windows NT / 2000 / XP)
- Doubts in C (C++)
- Junior Developer have some doubts in CF_SQL_NUMERIC (ColdFusion)
- how to upload Word doc with columns & graphics? (Graphics and Multimedia)
- C++ Syntax (C++)
Other Threads in the C++ Forum
- Previous Thread: How to use wifstream to read a unicode file..
- Next Thread: Doubts in i/o and others in 'C'
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






