By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,299 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

A bug with the cc compiler? leading printf is not allowed...

100+
P: 121
Here is my simply nothing meaningful code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. struct packetClass
  6. {
  7.    int sqnNO;
  8. };
  9.  
  10. typedef struct packetClass packet;
  11.  
  12. void function(packet **input);
  13. int main()
  14. {
  15.    packet *a;
  16.  
  17.    function(&a);
  18. }
  19.  
  20. void function(packet **input)
  21. {
  22.    printf("why?\n");
  23.    packet *node = *input;
  24. }
It could be compiled under gcc successfully and work fine.

However, if you run
Expand|Select|Wrap|Line Numbers
  1. cc gccvscc.c
Then it says:
Expand|Select|Wrap|Line Numbers
  1. charlie$ gcc gccvscc.c
  2. charlie$ cc gccvscc.c
  3. "gccvscc.c", line 23: syntax error before or at: *
  4. cc: acomp failed for gccvscc.c
  5. charlie$ 
I figured out that if you remove the printf statement, everything is fine with the cc compiler, but why would cc treat it like this?
Oct 15 '07 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
It's not the printf.

This is C and you cannot declare variables in the middle of a function. gcc reported it was in trouble when it saw the *. So, the error is from there to the left.

If you compile this using g++, the error goes away.
Oct 15 '07 #2

100+
P: 121
It's not the printf.

This is C and you cannot declare variables in the middle of a function. gcc reported it was in trouble when it saw the *. So, the error is from there to the left.

If you compile this using g++, the error goes away.
Thank you so much for your clarification.
Oct 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.