Thread: memory loss again

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    93

    memory loss again

    version gcc 2.95.3
    SunOS 5.6

    Hi,

    why can I not put a printf() at the beginning of a function ?

    I do not remember this being a problem, but at the moment I find this does not work

    Code:
    void function(int parameter)
    {
       printf("test");
    
       int variable;
    
       variable = 1;
    
       printf("value in variable is %d\n", variable);
    
    }
    whereas this works

    Code:
    void function(int parameter)
    {
       int variable;
    
       variable = 1;
    
       printf("test");
    
       printf("value in variable is %d\n", variable);
    
    }
    it appears as though an assigment has to be made before it is allowed, is this true ?


    example of error from a make:-

    gcc -c telex_filter.c -I../lib -I../common
    telex_filter.c: In function `telex_filter_process':
    telex_filter.c:86: parse error before `extern'
    make: *** [telex_filter.o] Error 1


    my reason for this, is to check what is coming into the function, i.e., what values are being passed in,



    tia,

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    Try this program with C++ compilers
    Saravanan.T.S.
    Beginner.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    93
    well, well

    thank you Salem, I never knew that, therefore I can just print out the arguments with a printf() statement placed after the declarations, excellent


    ty saravanan.T.S. that won't be necessary, as I'll need to keep these as C programs

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    102
    Oh!! I thought you knew this:
    In C, all variable declarations need to be before the first statement within a block
    Saravanan.T.S.
    Beginner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with insert/delete binary search tree
    By Nazgulled in forum C Programming
    Replies: 39
    Last Post: 03-25-2009, 04:24 PM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. Suggestions on this C style code
    By Joelito in forum C Programming
    Replies: 11
    Last Post: 06-07-2007, 03:22 AM
  5. Shared Memory - shmget questions
    By hendler in forum C Programming
    Replies: 1
    Last Post: 11-29-2005, 02:15 AM