How to write basic code

This is a discussion on How to write basic code within the C Programming forums, part of the General Programming Boards category; log.c Code: #include <types.h> #include <log.h> int log(int constant,void *value,int len) { dprintf("log(%d,%x,%d)\n\r",constant,value,len); return 0; } log.h Code: #include <types.h> ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    7

    How to write basic code

    log.c
    Code:
    #include <types.h>
    #include <log.h>
    
    int log(int constant,void *value,int len) 
    
    {
        dprintf("log(%d,%x,%d)\n\r",constant,value,len);
        return 0; 
    }
    log.h
    Code:
    #include <types.h>
    #include <imaging.h>
    
    #ifndef h_log
    #define h_log
    #define RES    8
    
    int log(int constant,void *value,int len);
    how do I write a test function for RES????
    Last edited by tingting; 07-21-2009 at 12:43 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What do you think "writ[ing] a test function for RES" even means? It's a constant.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    7
    okay, ma fault.

    how do I initiate the dprintfs?? it's a constant that can be passed to the int log ()

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So now, what does "initiate the dprintfs" mean? If you want to use RES in a function call, then do so:
    Code:
    log(RES, some_ptr, some_int);

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    7
    the program would watch for RES to change - if it changes to +2
    - do some calculations
    - pass it as a pointer
    - assign a length to the value and write to some memory address

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    RES can't change. It's a constant.

  7. #7
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    602
    First of all is your constant defined variable RES to be used in your log()? Are you including many other .h files which may or may not have #define RES /*some number */ ? You may then need to check, like you did for h_log, whether RES is defined. If this is to change you will need to use #undef, then re-define your RES constant. With your questioning, you left more questions than can be answered up for.

  8. #8
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Well, if you dont explain what excatly you want and what your actually after with the code, you wouldn't get any help. You hardly provide any information there.

    ~ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  9. #9
    Registered User
    Join Date
    Jul 2009
    Posts
    7
    I am trying to write a function will utilize the (constant, *value, len) as input parameters

    where do I start???

  10. #10
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Quote Originally Posted by tingting View Post
    I am trying to write a function will utilize the (constant, *value, len) as input parameters

    where do I start???
    What do you mean "utilize" them? What do you want this function to actually do?

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by tingting View Post
    I am trying to write a function will utilize the (constant, *value, len) as input parameters

    where do I start???
    The code you have already utilizes the constant, *value, and len as input parameters, as it needs them for the print statement. So I guess you're done.

  12. #12
    Registered User
    Join Date
    Jul 2009
    Posts
    7
    tabstop,

    for me to log anything to flash log section,
    - i need to test a condition whether it's been triggered, then in main.c, I need to call the initialization function to execute the log
    Last edited by tingting; 07-22-2009 at 02:24 PM.

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,670
    Why don't you post a stripped down example program of what you're trying to do?



    ITSA
    Socket Library!

  14. #14
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    This is just getting so funny. Why don’t just copy and paste a few bits of code here if you don’t want to say what you’re trying to do. It makes our life much easier at least.

    ~ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to write a C code that evaluates 7, 7, 7, 1 = 100
    By filanfistan in forum C Programming
    Replies: 8
    Last Post: 10-21-2005, 07:37 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. How do I write more efficient code?
    By minesweeper in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 11:08 AM
  4. Run Visual Basic code inside C++?
    By torbjoen in forum Windows Programming
    Replies: 8
    Last Post: 07-31-2002, 11:41 PM
  5. How to write code to change the printer resolution
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 07-26-2002, 06:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21