User Profile

Collapse

Profile Sidebar

Collapse
dissectcode2
dissectcode2
Last Activity: Dec 16 '11, 11:21 PM
Joined: Apr 2 '09
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • dissectcode2
    replied to Help with #defines at compile time.
    in C
    thanks both.

    your suggestion donbock of prefixing __MODULE__ is brilliant and i was trying that but it seems that when I use ## to combine __MODULE__, which is the name of the module like moduleA (just plain, not a string) with something like ID_ there is a prescendence issue and it doesn't work:

    Code:
    #define __MODULE__ moduleA
    #define MODULE (ID_ ## __MODULE__)
     
    // so want to test that ID_moduleA
    ...
    See more | Go to post

    Leave a comment:


  • dissectcode2
    started a topic Help with #defines at compile time.
    in C

    Help with #defines at compile time.

    hi! I have these two different macros; one is a scaled down version of the other. I have a header where I need to choose which macro to use for every module in my firmware (~100 modules), at compile time. Here is an example of what I'm trying to do, but I know this macro doesn't work because I can't have multiple directives on the same line...

    Code:
    enum DEBUG_LEVEL{ none, medium, high }
    
    #define DBG(module,
    ...
    See more | Go to post

  • gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)


    i couldn't find a flag to collapse multiple instances of a macro but that would be my ideal solution.

    if i define the myname array in each (~150) header, i have to add a parameter to my assert macro or is there something magical happening in the background?

    Code:
    #define assert(e, f) ....
    See more | Go to post

    Leave a comment:


  • You're right donblock : I should have mentioned what the modified assert does. We have to use _assert because we are printing stuff over a serial port using our own API, and it prints out a message and line number and from which module the error came from. And, the "e" should have been #e - it copied from the wrong ifdef...

    I am working on fw and am running out of space, and from what I understand, macros are always expanded...
    See more | Go to post

    Leave a comment:


  • Way to retrieve calling function's ID to print an error?

    Hi - I am trying to replace a macro:

    myassert(e) ((e) ? (void)0 : _assert(__FILE_ _, __LINE__, "e"))

    which is used in ~800 places in my code and it's taking up too much space. I want to replace it with a single function call which tests for 0, but I still need to print the line number and file name where the error came from. Is there a way in C to get that info?? thank you
    See more | Go to post

  • dissectcode2
    started a topic Testing for unreachable code.
    in C

    Testing for unreachable code.

    Hi - Is there a trick that you experts out there use or know of to test for unreachable code? Some code / function might be called by another piece of code, and so on....but what if that path is never taken? Therefore, it's not caught by the compiler as "unused"... I wish there was a way to search for "unexplored ". Any ideas?
    See more | Go to post

  • dissectcode2
    replied to STRCPY seg fault
    in C
    I FOUND THE ANSWER!!!

    http://stackoverflow.com/questions/1...-into-c-string

    relief!!...
    See more | Go to post

    Leave a comment:


  • dissectcode2
    started a topic STRCPY seg fault
    in C

    STRCPY seg fault

    I know this is a common forum post but I don't see how they fit with my code/problem:

    Code:
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void cds( char *cdsprefix )
    {
    
        // default
        char *prefix = "somereally_long_string_09";
    
        if( cdsprefix )
        {
    
    	printf("we passed in a prefix...\n\n");
    ...
    See more | Go to post

  • thank you weaknessforcats because i was going crazy with a seg fault, and thought it might have something to do with all strcat's, and you validated it with good info. now i know what is the correct approach.
    See more | Go to post

    Leave a comment:


  • or would it have been better to use scanf ??
    See more | Go to post

    Leave a comment:


  • I wish I could delete this post because I realized my sprintf needed %d inside and it worked. I'm smarter than I thought. pat pat
    See more | Go to post

    Leave a comment:


  • dissectcode2
    started a topic Need help concatentating 2 strings and an int.
    in C

    Need help concatentating 2 strings and an int.

    Hi - please help. I have two strings and a number which I need to concatenate together and I'm confused to what is the best approach. Here is my code:

    Code:
    char *s1 = "iamafilename_";
    char *s2 = ".tif";
    
    int i;
    for( i = 0; i < 10; i++ )
    {
    
     char itoaBuff[100];
     int num_len = sprintf(itoaBuff, "%s", i);
    
     char *f = (char *)malloc( (strlen(s1)
    ...
    See more | Go to post

  • dissectcode2
    started a topic How to create a directory in C
    in C

    How to create a directory in C

    Sorry for this boring noob question but I found a lot of answers via google for C++ and other languages but I need help with C


    I want to create a directory if it doesn't exist.

    Can I use mkdir in C? But is that compatible if someone ran my program on Windows cmd?

    thanks
    See more | Go to post

  • dissectcode2
    started a topic Why (cast) when we don't have to?
    in C

    Why (cast) when we don't have to?

    I was just reading in K&R page 44-45 that "conversion s take place across assignments; the value of the right side is converted to the type on the left, which is the type of the result......If x is float and i is int, then x = i and i = x both cause conversions; float to int causes truncation"

    so if I can type:

    Code:
    int i;
    float f;
    
    i = f; // and f = i;
    ...
    See more | Go to post

  • dissectcode2
    replied to 2 unsigned shorts make a signed int ???
    in C
    where can I find these rules? I searched the GNU C Library Reference Manual and GNU Compiler Collection manual and I can't find the rules you posted above in either one. thanks so much for helping!
    See more | Go to post

    Leave a comment:


  • dissectcode2
    started a topic 2 unsigned shorts make a signed int ???
    in C

    2 unsigned shorts make a signed int ???

    I have something funny happening when I compile (gcc)

    I have two variables:

    Code:
    unsigned short x;
    unsigned short y;

    and when I used them in a for loop condition:

    Code:
    unsigned int i;
    for( i = 0 ; i < x * y ; i++ )
    { ; }

    I get a compiler warning:
    " warning: comparison between signed and unsigned "...
    See more | Go to post

  • dissectcode2
    started a topic What is a Good IDE for C development (on Linux) ?
    in C

    What is a Good IDE for C development (on Linux) ?

    Hi - I am on a Linux machine programming in C and I am currently using Emacs. I am comfortable with it, and I like the shortcuts but I am also like using IDEs like I do for Java development (Eclipse and NetBeans). What is a good FREE IDE for C programming ? thanks!!!
    See more | Go to post

  • AH I needed to cast one more layer! I didn't see that, thanks...
    See more | Go to post

    Leave a comment:


  • Help with a pointer. Dereferencing a null pointer issue.

    Hi

    This is kind of a noob C question although I'm not really one anymore.

    I have this simple function which processes a button press:

    Code:
    void ButtonAction( Button *button, Mode mode )
    {
        Button *b = (Button *)((button)->actions[(mode)];
    
        if( mode == RepeatPress ) // some enum val
    	  *(b->actions[RepeatPress]) = EventMultiStepLeft;
    ...
    See more | Go to post

  • There is a \\ between Program and Files? I tried the \\ in every other spot, and it is the same error (actually that is how I have it in my code, correctly)
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...