GCC problem - Linux

This is a discussion on GCC problem - Linux ; I switched my code over to using what I believe to be the K&R style function definitions. 63 /*pcap_loop callback routine*/ 64 void 65 capture_callback(buffer, packet_header, data) 66 u_char *buffer, const struct pcap_pkthdr *packet_header, u_char *data; 67 { 68 total_captured_packets++; ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: GCC problem

  1. GCC problem

    I switched my code over to using what I believe to be the K&R style
    function definitions.

    63 /*pcap_loop callback routine*/
    64 void
    65 capture_callback(buffer, packet_header, data)
    66 u_char *buffer, const struct pcap_pkthdr
    *packet_header, u_char *data;
    67 {
    68 total_captured_packets++;
    69 if (display == true)
    70 {
    71 fprintf(stdout, "Received packet %d\n");
    72 }
    73 if (cache_packets == true)
    74 {
    75 struct packetCache *pc;
    76 if ((pc = malloc(sizeof *pc + packet_header->len)) ==
    NULL)
    77 {
    78 fprintf(stderr, "Memory Allocation Error!\n");
    79 fprintf(stderr, "Turning off caching\n");
    80 cache_packets = false;
    "packman.c" 230L, 5444C written
    sysadmin@devbox:~/projects/packet_capture$ gcc -c packman.c
    packman.c: In function ‚capture_callback‚:
    packman.c:66: error: expected identifier or ‚(‚ before ‚const‚
    packman.c:76: error: invalid type argument of ‚->‚


  2. Re: GCC problem

    westymatt wrote:
    > I switched my code over to using what I believe to be the K&R style
    > function definitions.


    That would be incredibly stupid. The simple reason is that it's
    old&deprecated and non-standard. Any compiler worth its name should reject
    it, unless explicitly instructed to do otherwise.

    Uli


  3. Re: GCC problem

    On Wed, 18 Jul 2007 07:19:17 +0000, westymatt wrote:

    > I switched my code over to using what I believe to be the K&R style
    > function definitions.
    >
    > 63 /*pcap_loop callback routine*/
    > 64 void
    > 65 capture_callback(buffer, packet_header, data)
    > 66 u_char *buffer, const struct pcap_pkthdr
    > *packet_header, u_char *data;
    > 67 {
    > 68 total_captured_packets++;
    > 69 if (display == true)
    > 70 {
    > 71 fprintf(stdout, "Received packet %d\n");
    > 72 }
    > 73 if (cache_packets == true)
    > 74 {
    > 75 struct packetCache *pc;
    > 76 if ((pc = malloc(sizeof *pc + packet_header->len)) ==
    > NULL)
    > 77 {
    > 78 fprintf(stderr, "Memory Allocation Error!\n");
    > 79 fprintf(stderr, "Turning off caching\n");
    > 80 cache_packets = false;
    > "packman.c" 230L, 5444C written
    > sysadmin@devbox:~/projects/packet_capture$ gcc -c packman.c
    > packman.c: In function √Ęcapture_callback√Ę:
    > packman.c:66: error: expected identifier or √Ę(√Ę before √Ęconst√Ę
    > packman.c:76: error: invalid type argument of √Ę->√Ę


    You should buy the second edition before doing that.

    --
    Mike McGinn
    "more kidneys than eyes!"

  4. Re: GCC problem

    westymatt wrote in news:1184743157.214777.263570
    @z28g2000prd.googlegroups.com:

    > I switched my code over to using what I believe to be the K&R style
    > function definitions.


    As others have already noted, that's not a terribly sane thing to do. I
    really can't imagine why you would want to do so. However gcc will still
    happily accept the code if you give it proper K&R syntax.

    > 63 /*pcap_loop callback routine*/
    > 64 void
    > 65 capture_callback(buffer, packet_header, data)
    > 66 u_char *buffer, const struct pcap_pkthdr
    > *packet_header, u_char *data;


    The function arguments should be separated by semicolons:

    void capture_callback(buffer, packet_header, data)
    u_char *buffer;
    const struct pcap_pkthdr *packet_header;
    u_char *data;
    {
    /* function body */
    }

    Also, you should know that the keywords "const" and "void" did not exist
    back in original K&R days.


    GH

+ Reply to Thread