[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



Preben Mikael Bohn 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?
> 
> Hvad med sizeof? Har ikke prøvet, men burde vel egentlig virke? Hvad skal
> du egentlig bruge det til ved compile-time?

Det er i forbindelse med opgaven "Printing numbers in different bases" nævnt 
på http://www.daimi.au.dk/dOvs/exercises/week39/assignmenttex

For at løse den definerer jeg bl.a. et alfabet 
"0123456789abcdefghijklmnopqrstuvxwz", hvor længden af alfabetet er en øvre 
grænse for hvor stor en base programmet understøtter. Hvis jeg vælger at 
udvide alfabetet ved at rette i kildekoden så skal længden opdateres 
tilsvarende og det kan lige så godt gøres på compile-time i stedet for 
run-time når nu alfabetet er givet på forhånd.

(Jeg kunne selvfølgelig gøre programmet mere fleksibelt og derved undgå et 
hardcodet alfabet, men så meget gider jeg ikke gøre ud af det taget 
programmets anvendelighed i betragtning.)

-- 
Jonas Kongslund    <jonas(at)kongslund.dk>     http://www.kongslund.dk/
The programmer, like the poet, works only slightly removed from pure
thought-stuff. He builds his castles in the air, from air, creating by
exertion of the imagination. [Brooks, The Mythical Man-Month]


 
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] *