473,378 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Unreadable source code

I have been looking at "sh" source code and have found this strange
thing:

/**** syntax.c ****/
#define ndx(ch) (ch + 1 - CHAR_MIN)
#define set(ch, val) [ndx(ch)] = val,
#define set_range(s, e, val) [ndx(s) ... ndx(e)] = val,

/* character classification table */
const char is_type[257] = { 0,
set_range('0', '9', ISDIGIT)
set_range('a', 'z', ISLOWER)
set_range('A', 'Z', ISUPPER)
set('_', ISUNDER)
set('#', ISSPECL)
set('?', ISSPECL)
set('$', ISSPECL)
set('!', ISSPECL)
set('-', ISSPECL)
set('*', ISSPECL)
set('@', ISSPECL)
};
/**** !syntax.c ****/
/**** gcc -E syntax.c ****/
const char is_type[257] = { 0,
[( '0' + 1 - (-0x7f-1) ) ... ( '9' + 1 - (-0x7f-1) ) ] =
01 ,
[( 'a' + 1 - (-0x7f-1) ) ... ( 'z' + 1 - (-0x7f-1) ) ] =
04 ,
[( 'A' + 1 - (-0x7f-1) ) ... ( 'Z' + 1 - (-0x7f-1) ) ] =
02 ,
[( '_' + 1 - (-0x7f-1) ) ] = 010 ,
[( '#' + 1 - (-0x7f-1) ) ] = 020 ,
[( '?' + 1 - (-0x7f-1) ) ] = 020 ,
[( '$' + 1 - (-0x7f-1) ) ] = 020 ,
[( '!' + 1 - (-0x7f-1) ) ] = 020 ,
[( '-' + 1 - (-0x7f-1) ) ] = 020 ,
[( '*' + 1 - (-0x7f-1) ) ] = 020 ,
[( '@' + 1 - (-0x7f-1) ) ] = 020 ,
};
/**** !gcc -E syntax.c ****/

It compiles without error message or warning. Does somebody have an
explanation of this portion of source code ?
Nov 14 '05 #1
1 2509
In article <75*************************@posting.google.com>
Ellixis <he***@phpbb-fr.com> writes:
I have been looking at "sh" source code and have found this strange
thing:

/**** syntax.c ****/
#define ndx(ch) (ch + 1 - CHAR_MIN)
#define set(ch, val) [ndx(ch)] = val,
The first macro simply offsets a value (named ch, and without
parentheses so that the macro misbehaves if "ch" is an expression
using an operator such as "&" -- e.g., ndx(1 & 3) does not work
"as desired") by 1-CHAR_MIN, typically 1-(-128) or 1-0. In
other words, it generally adds either 129 or 1.

The second macro is designed to use the C99 "designated initializer"
syntax.
#define set_range(s, e, val) [ndx(s) ... ndx(e)] = val,
This macro produces a syntax error.

(GCC has an extension in which this error becomes valid and
meaningful, but this extension is *not* valid C99.)
/* character classification table */
const char is_type[257] = { 0,
set_range('0', '9', ISDIGIT)
This uses the GCC extension to make sure that is_type[ndx('0')] is set
to ISDIGIT, is_type[ndx('1')] is set to ISDIGIT, is_type[ndx('2')] is
set to ISDIGIT, and so on, through is_type[ndx('9')]. Since Standard
C requires that the integer values of '0' through '9' be contiguous
and sequential, this always works (provided your compiler implements
the GCC extension).
set_range('a', 'z', ISLOWER)


This uses the GCC extension to make sure that is_type[ndx('a')] is
set to ISLOWER, etc., as before. It causes is_type[ndx(various
EBCDIC non-letter characters)] *also* to be ISLOWER, i.e., it does
not work on many IBM mainframes. (It assumes instead that you are
using ASCII. There *are* GCC ports to IBM mainframes, but presumably
either the code will be run in "ASCII mode" or else this program
will never be compiled for use in "EBCDIC mode".)

[Remainder snipped; it all works along the same lines.]

The new C99 syntax is, e.g.:

int a[10] = { [3] = 42, [9] = -1 };
/* sets a[] to the sequence {0,0,0,42,0,0,0,0,0,-1} */

and:

struct blah { int i; double d; char *s; };
struct blah x = { .s = "hello" };
/* sets x.i to 0, x.d to 0.0, and x.s to point to "hello" */

Again, these are called "designated initializers", because you
designate (name) the element to initialize. (Actually, the draft
of C99 I use just calls them "designators" and does not have a
formal term for the designator=value sub-syntax.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Mike B | last post by:
How do you make it source your source code is unreadable? I went to a website and tried to look at their source, and it came up blank. I then saved the file and got a message saying something...
11
by: alex | last post by:
Hi all, I'd like to find a way to make a part of my code unreadable from users when they look at the source of my web page. It is possible ? I thought of using...
3
by: Won Lee | last post by:
I made my own from which is similiar to a MsgBox but allows for positioning on the screen. If I call the class from a button event it works fine. The form, however, becomes unreadable if I call...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.