[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Bestemme længde af streng på compile-time



On Mon, 23 Sep 2002, Jonas Kongslund wrote:

> Hvis jeg har defineret en streng
>   char *foo = "flaf\0";
> er det så muligt at bestemme og lagre dets længde i en anden variabel 'int 
> bar' på compile-time?
> 
> Jeg kan selvfølgelig bare hardcode 'int bar = 4', men det er for træls at 
> vedligeholde såfremt foo ændres til en streng med anden længde end 4.

#include <stdio.h>

const char foo[] = "fluffer ged";

int main () {
  printf("sizeof *foo: %i\n", sizeof(foo));
  printf("foo er %s", foo);
  return 0;
}

...
sizeof *foo: 12
foo er fluffer ged

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
I don't say this lightly. However, I really think that the U.S. no longer
is classifiable as a democracy, but rather as a plutocracy.
                               - H. Peter Anvin



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *